Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] I cannot understand this output....pls explain.

Expand Messages
  • Jeff 'japhy' Pinyan
    ... You are not using warnings. Your code should always have use warnings; in it if you re using Perl 5.6 or later. If you re still using Perl 5.005, then
    Message 1 of 3 , Feb 3, 2004
    • 0 Attachment
      On Feb 4, fd97616 said:

      >$a = "Hello";
      >$b = "world";
      >
      >if ($a == $b){
      > print "Fine\n";
      >}

      You are not using warnings. Your code should always have

      use warnings;

      in it if you're using Perl 5.6 or later. If you're still using Perl
      5.005, then your #! line should look like

      #!/usr/bin/perl -w

      >so actaully means that $a is equal to $b...

      You would know why if you had warnings on. The == operator is for NUMERIC
      equality. To compare strings, use 'eq'.

      Read 'perldoc perlop' for the full list of numeric and stringic comparison
      operators.

      --
      Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
      RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
      <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
      [ I'm looking for programming work. If you like my work, let me know. ]
    • rrreddy0211
      Hi, == is a numeric comparsion operator, so it assumes variables to be in numeric form. Since here variable values are non-numeric, they are treated as zeros
      Message 2 of 3 , Feb 4, 2004
      • 0 Attachment
        Hi,

        == is a numeric comparsion operator, so it assumes variables to be in
        numeric form. Since here variable values are non-numeric, they are
        treated as zeros and hence the result will be true and 'fine'
        statement is printed out.

        Hope this is clear.

        - Reddy.

        --- In perl-beginner@yahoogroups.com, "fd97616" <fd97616@y...> wrote:
        > $a = "Hello";
        >
        > $b = "world";
        >
        > if ($a == $b){
        > print "Fine\n";
        > }
        >
        >
        > this is the code....
        > here the Fine is getting printed....
        >
        > so actaully means that $a is equal to $b...
        > how is that possible.....
        > I cannot understand this.
        >
        > can someone please explain this to me.
        > thanks.
        > kaushik.
      Your message has been successfully submitted and would be delivered to recipients shortly.