Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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
Replies are listed 'Best First'.
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 10:39 UTC
    Redo experiment using "4test" instead of "test" for yet more thrills and amazement ;-)

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

Re: Something interesting i found today
by Anonymous Monk on Aug 24, 2013 at 07:53 UTC

      Larry wills it!

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 lurking in the Monastery: (19)
As of 2015-07-30 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls