in reply to Re^7: How can I set a bit to 0 ?
in thread How can I set a bit to 0 ?

you seem to miss that he's using constants

You seem to assume that he's using constants ;-)

Unfortunately, he hasn't provided the definitions of those labels, let alone an SSCCE, so it's all guesswork.


🦛

Replies are listed 'Best First'.
Re^9: How can I set a bit to 0 ?
by LanX (Saint) on May 27, 2022 at 14:08 UTC
    > You seem to assume that he's using constants

    Question: is there any other strict explanation for barewords as operands?

    I've seen this pattern so many times with modules exporting flags and IIRC even perldocs°, that this discussion is surprising me.

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

    update

    °) see last paragraph in chmod

      You can also import the symbolic S_I* constants from the Fcntl module:

      use Fcntl qw( :mode ); chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; # Identical to the chmod 0755 of the example above.
      Question: is there any other strict explanation for barewords as operands?

      Sure, any subs will do - they don't have to be constants:

      #!/usr/bin/env perl use strict; use warnings; sub upload () { rand 50 } sub getTicket () { rand 60 } sub downLoading () { rand 70 } sub printCLine { print shift } # Start of bartender1382 code my $stats = 0; $stats = upload | getTicket | downLoading; printCLine ($stats); # End of bartender1382 code

      🦛

        > Sure, any subs will do - they don't have to be constants:

        you mean any sub with empty prototype which is the way how constants are implemented in constant

        see https://perldoc.perl.org/perlsub#Constant-Functions °

        and the OP's code still compiles even if your return values are not constant.

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

        °) NB:

          sub FLAG_MASK () { FLAG_FOO | FLAG_BAR } sub FOO_SET () { 1 if FLAG_MASK & FLAG_FOO }