Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^9: How can I set a bit to 0 ?

by LanX (Saint)
on May 27, 2022 at 14:08 UTC ( [id://11144226]=note: print w/replies, xml ) Need Help??


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

> 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.

Replies are listed 'Best First'.
Re^10: How can I set a bit to 0 ?
by hippo (Bishop) on May 27, 2022 at 14:18 UTC
    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 }
        and the OP's code still compiles even if your return values are not constant.

        Yes, that's entirely my point. :-)


        🦛

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-26 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found