The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


bitflags - Perl module for generating bit flags


  use bitflags qw( ALPHA BETA GAMMA DELTA );
  use bitflags qw( EPSILON ZETA ETA THETA );
  use bitflags qw( :start=2 BEE CEE DEE EEE EFF GEE );
  use bitflags qw( :start=^3 EIGHT SIXTEEN THIRTY_TWO );


The bitflags module allows you to form a set of unique bit flags, for ORing together. Think of the O_ constants you get from Fcntl... that's the idea.

Successive calls remember the previous power used, so you don't have to set a starting number, or declare all the constants on one line.

If you do want to set a starting value, use the :start flag as the first argument in the import list. If the flag is :start=NNN, where NNN is some positive integer, that value is checked to ensure it's a power of two, and that value is used as the starting value. If it is not a power of two, the program will croak. If the flag is :start=^NNN, where NNN is some positive integer, that value is the power of two to start with.


The flags are created as ()-prototyped functions in the caller's package, not unlike the constant pragma.


Jeff "japhy" Pinyan.




Online at: japhy on #perl on DALnet and EFnet. japhy at japhy at "Coding With Style" column at