in reply to Changing a number to a string
i'm amazed no one's brought up merlyn's solution yet:
This is taken verbatim from Effective Perl Programming. Not sure if it will work correctly when dealing with a "0" string, but it's worth testing (give me a couple minutes :)"$_ is string\n" if (~$_ & $_) ne '0';
jynx
Update:that's cool! if you declare:
Notice it only outputs the one that looked like a string. That merlyn's a genius.my $string = "0"; my $num = 0; # then we: print "string: $string is a string.\n" if ((~$string & $string) ne '0' +); print "num: $num is a string.\n" if ((~$num & $num) ne '0');
For more information on why this works read page 248 of Effective Perl Programming...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Changing a number to a string
by merlyn (Sage) on Feb 02, 2001 at 21:14 UTC |