Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Something interesting i found today

by perlaintdead (Scribe)
on Aug 24, 2013 at 06:35 UTC ( #1050769=perlquestion: print w/ replies, xml ) Need Help??
perlaintdead has asked for the wisdom of the Perl Monks concerning the following question:

"test" - 42 is -42
"test" + 42 is 42
"test" / 42 is 0
"test" * 42 is 0

Any specific reasons PERL does this. Also this might make for an interesting obfu trick.

Comment on Something interesting i found today
Select or Download Code
Re: Something interesting i found today
by Corion (Pope) on Aug 24, 2013 at 06:50 UTC

    In Perl, the operators determine the type of their arguments. The numeric operators treat strings as numbers, and things that don't look like a number get treated as zero.

    This explains all your four cases.

Re: Something interesting i found today
by moritz (Cardinal) on Aug 24, 2013 at 07:00 UTC

      The implication that use warnings; was not present to start with is somewhat disturbing. Can one infer that use strict; is also not a habit?

        this was in my "test.pl" when ever i need to test a theory or to just see what happens (the latter in this case) i use this and i don't need to use strict and warnings to test theorys
Re: Something interesting i found today
by Anonymous Monk on Aug 24, 2013 at 07:53 UTC

      Larry wills it!

Re: Something interesting i found today
by Anonymous Monk on Aug 24, 2013 at 10:39 UTC
    Redo experiment using "4test" instead of "test" for yet more thrills and amazement ;-)

      oooohhh mmyyy GGGOOOOOOOOODDDDDDD!!!!!!!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050769]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-12-28 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls