in reply to Changing a number to a string

It could also have something to do with the way you initialize it.
# initializing like this will represent '0' as a number $foo = 0; # by double quoting it, the '0' should be seen as a string $foo = "0";
- kel -

Replies are listed 'Best First'.
Re: Re: Changing a number to a string
by myocom (Deacon) on Jan 25, 2001 at 23:25 UTC

    How would you know if it's being seen as a string or a number, though? Because once you try to test that, Perl will just Do The Right Thing anyway.

    $foo = 0; # Declaring as a number if ($foo eq '0') { print "Oops, it's a string!\n"; } $foo = "0"; # Declaring as a string if ($foo == 0) { print "Oops, now it's a number!\n"; }

    Bottom line: Perl will always Do The Right Thing when it comes to worrying about stringifying numbers or number-fying strings.

      FYI, I think the "standard" hack for seeing if a scalar has been used in a string context is ^, but it isn't a very good hack.

      I mean to write a module that exposes what types of values a scalar already has cached as well as nifty calls like looks_like_number().

              - tye (but my friends call me "Tye")