Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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 taking refuge in the Monastery: (6)
As of 2019-09-20 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (253 votes). Check out past polls.

    Notices?