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

If you write "$ary[0] = '12'", you assign the value "'12'" to $ary[0]. Perhaps you were thinking of "$ary[0] == '12'"?
  • Comment on Re: Interpreting values alternately as $trings and Integers = confused response by Perl
  • Select or Download Code

Replies are listed 'Best First'.
(elbie): Interpreting values alternately as $trings and Integers = confused response by Perl
by elbie (Curate) on Apr 14, 2002 at 20:07 UTC
    Note that perl has two different kinds of comparison operators, one for strings (eq) and one for numerical values (==)

    Minor point, but you should probably use $arr[0] == 12 to get a true numerical comparison. i.e. Drop the quotes.

    elbieelbieelbie

      I agree that the quotes should probably be removed, but for reasons of clarity -- that is, people are likely to glance at the code and accidentally interpret the == as an eq due to seeing quotes. == does "true numerical comparison" whether or not there are quotes there; the string gets converted to a number for the ==, and it DWYM.