Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Counter Intuitive Code

by Corion (Pope)
on Mar 27, 2019 at 14:41 UTC ( #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
Node Status?
node history
Node Type: note [id://1231749]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2019-11-16 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?