in reply to Interpreting values alternately as $trings and Integers = confused response by Perl

} elsif ($ary[0] = '12') { and found that $ary[0] was being assigned a value of 12.

Relational operators String Number Equal eq == Not equal ne != Greater gt > Greater or equal ge >= Less lt < Less or equal le <= Compare cmp <=>
As you can see, = is not a relational operator that test equality. What is it then? It's the assignment operator.

You assigned 12 to $ary[0], and an assignment returns the assigned value, so the entire $ary[0] = '12' expression returns 12, which evaluates to true in boolean context. You probably meant == or eq, depending on how you want to see things. If you use ==, drop the quotes so that Perl doesn't have to convert the string 12 to the number 12.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

  • Comment on Re: Interpreting values alternately as $trings and Integers = confused response by Perl
  • Select or Download Code