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

> Most probable reason you are seeing what you saw -> you did "use feature 'bitwise'" earlier in your debugging session. bitwise forces plain | to numeric.

There was no "use feature 'bitwise'" inside the debugger.

:~$ perl -de0 Loading DB routines from perl5db.pl version 1.77 ... DB<1> say (0 . "$_" | 1 . "1") for qw/0 2 4 6 8/ 11 11 15 15 11 DB<2>

but the interactive debugger seems to automatically run under -E

  • E commandline
    behaves just like -e, except that it implicitly enables all optional features and builtin functions (in the main compilation unit). See feature and builtin.
  • Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    Replies are listed 'Best First'.
    Re^11: converting binary to decimal
    by tybalt89 (Monsignor) on Jun 08, 2025 at 14:21 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

    Re^11: converting binary to decimal
    by harangzsolt33 (Deacon) on Jun 08, 2025 at 15:32 UTC
      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