in reply to Re: Changing a number to a string
in thread Changing a number to a string

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.

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

    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")