Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^9: converting binary to decimal

by tybalt89 (Monsignor)
on Jun 08, 2025 at 00:19 UTC ( [id://11165311]=note: print w/replies, xml ) Need Help??


in reply to Re^8: converting binary to decimal
in thread converting binary to decimal

Er, Umm, no.

$ perl -le 'print(0 . $_ | 1 . 1) for qw/0 2 4 6 8/' 11 13 15 17 19
Most probable reason you are seeing what you saw -> you did "use feature 'bitwise'" earlier in your debugging session. 'bitwise' forces plain | to numeric.

voodoo89 tybalt89 looks around for more chickens...

Replies are listed 'Best First'.
Re^10: converting binary to decimal
by LanX (Saint) on Jun 08, 2025 at 11:06 UTC

      Good catch!

      Quick test: if say 1 |. 2 does NOT give an error, you're running with use feature 'bitwise';

        These are the features automatically activated in the debugger
        use feature 'current_sub', 'bitwise', 'evalbytes', 'fc', 'isa', 'p +ostderef_qq', 'say', 'signatures', 'state', 'unicode_strings', 'unico +de_eval';
        Tested for 5.036000.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

      Wait. Are you saying that if someone has "use feature 'bitwise' in their header, then this code fails? How do I make sure it doesnt? Can I write "no feature 'bitwise';" inside binary2decimal() to make sure it doesn't misbehave? Or is that unnecessary?
        > Wait. Are you saying that if someone has "use feature bitwise in their header, then this code fails?

        If it's in the same scope, yes.

        Not sure what header means for you.

        > Can I write "no feature 'bitwise';" inside binary2decimal() to make sure it doesn't misbehave?

        Theoretically yes, try it out.

        Better use feature bitwise and change the operator to |. ... But this wouldn't work in older Perl.

        So in case backwards compatibility is an issue, maybe no combined with if Version >...

        In general, if someone was copying that code into his scope, you shouldn't be bothered about their fate. It's their responsibility.

        The right approach of sharing code is to use modules, not boilerplating.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2025-11-14 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (71 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.