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

Re: Counter Intuitive Code

by Corion (Patriarch)
on Mar 27, 2019 at 14:41 UTC ( [id://1231749]=note: print w/replies, xml ) Need Help??


in reply to Counter Intuitive Code

What you get is the string-biwise-or, not the number-bitwise-or:

perl -wle "print '16'|'8'" 96 perl -wle "print '1'|'8'" 9

If you tell Perl that you want the things to be really treated as numbers, the bitwise-or operator acts on the numerical representations:

perl -wle "print 0+'16'|0+'8'" 24

Prefixing 0+ in front of an expression is the canonical way in Perl to make a value be treated more as a number.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found