Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

Re: Whatever happened to chomp?

by Limbic~Region (Chancellor)
on Dec 14, 2003 at 09:58 UTC ( [id://314640]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Whatever happened to chomp?

zentara,
I am pretty sure this has nothing to do with chomp, but with Perl always trying to DWYM. Reading perldoc perlop I see that == will return true if the two arguments are numerically equal. Consider the following:
perl -e 'print "yeah\n" if "p2p" == "f2b"'
I am not sure if the behavior is well documented though.

Cheers - L~R

Replies are listed 'Best First'.
Re: Re: Whatever happened to chomp?
by CombatSquirrel (Hermit) on Dec 14, 2003 at 10:24 UTC
    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.
      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

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://314640]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.