Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Whatever happened to chomp?

by CombatSquirrel (Hermit)
on Dec 14, 2003 at 15:24 UTC ( [id://314641]=note: print w/replies, xml ) Need Help??


in reply to Re: Whatever happened to chomp?
in thread Whatever happened to chomp?

L~R:
perl -e "use warnings; print qq{yeah$/} if 'p2p' == 'f2b'; print 'p2p' + + 0" Argument "f2b" isn't numeric in numeric eq (==) at -e line 1. Argument "p2p" isn't numeric in numeric eq (==) at -e line 1. Argument "p2p" isn't numeric in addition (+) at -e line 1. yeah 0
Non-numeric arguments are treated as 0 in numeric operations. == is a numeric comparision operator, its string equivalent being eq.
I remember reading somewhere (maybe the camel or llama book) that numbers in string representations may have a newline character after them, which would explain why you don't need to chomp. I couldn't find the passage, though.
Cheers,
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re: Re: Re: Whatever happened to chomp?
by diotalevi (Canon) on Dec 14, 2003 at 19:57 UTC

    You are thinking of '3bar' == '3foo'. It doesn't matter what is after the number, the numeric value of a string with leading digits is the decimal value of those digits. Strings without leading digits are equal to zero.

Re: Re: Re: Whatever happened to chomp?
by Limbic~Region (Chancellor) on Dec 14, 2003 at 15:46 UTC
    CombatSquirrel,
    The missing warnings and strictures were intentional. I was trying to demonstrate the extent Perl would go to try and DWYM. I guess I should have been more clear - thanks.
    perl -e 'print "yeah\n" if "3p" == "f2b"'
    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://314641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found