logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

String::Binary::Interpolation - make it easier to interpolate binary bytes into a string

Author

       David Cantrell <david@cantrell.org.uk>

Bugs

       Bug reports and requests for extra features should be made on Github.

But Why!?!?!?

       Bit-fields, dear reader. If you are writing data to a binary file, and that file contains bytes (or even
       longer words) which are bit-fields, it is easier to have the bits of the bit-field right there in your
       string instead of having to glue the string together from various parts, and it's far easier to read than
       the frankly evil hack of embedding an array-ref.

Name

       String::Binary::Interpolation - make it easier to interpolate binary bytes into a string

Ok, So What Does It Do?

       When you "use" the module all it does is create a bunch of varliables in your namespace. They are named
       from $b00000000 to $b11111111 and their values are the corresponding characters. NB that when writing
       files containing characters with the high-bit set you need to be careful that you read and write bytes
       and not some unicode jibber-jabber.

See Also

       perlop's section on quote and quote-like operators

perl v5.36.0                                       2023-11-18                 String::Binary::Interpolation(3pm)

Source Code Repository

       <https://github.com/DrHyde/perl-modules-String-Binary-Interpolation>

Synopsis

       Where you would previously have had to write something like this ...

           my $binary = "ABC@{[chr(0b01000100)]}E"

       or ...

           my $binary = 'ABC'.chr(0b01000100).'E';

       to interpolate some random byte into a string you can now do this ...

           use String::Binary::Interpolation;

           my $binary = "ABC${b01000100}E";

       which I think you'll agree is much easier to read.

See Also