String...olation(3pm)

πŸ’– String...olation(3pm) β€” the String::Binary::Interpolation glow-up πŸ’–

okay bestie, gather round, because this is the manual page for String::Binary::Interpolation (yes, the manpage itself is filed under that cute little String...olation(3pm) abbreviation, we love a nickname) and it is genuinely going to change your whole binary-writing era. 🌸


✨ NAME ✨

String::Binary::Interpolation β€” making it easier to interpolate binary bytes into a string. no cap. that's the whole job. πŸ’…


🌈 SYNOPSIS 🌈

so like, before? before was rough. before, if you wanted to shove a random byte into a string, you had to do one of these little horrors:

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

or this one:

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

and like… they work. they're just giving unreadable. 😭

but now? now you can do this:

use String::Binary::Interpolation;

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

which, and I think you'll agree with me here, is so much easier to read. it's giving clarity. it's giving main character energy. 🫢


πŸ’€ BUT WHY!?!?!? πŸ’€

Bit-fields, dear reader. πŸ’œ

okay so real talk: if you're writing data to a binary file, and that file has bytes in it (or even longer words, bestie, we're not limiting ourselves) which are bit-fields, it is so much easier to just have the bits of the bit-field sitting right there in your string. right there!! in the string!! instead of gluing the whole thing together from a million separate parts like some kind of craft project.

and it is far easier to read than that frankly evil hack of embedding an array-ref. we don't do that here. not anymore. πŸ™ˆ


πŸ‘‘ OK, SO WHAT DOES IT DO? πŸ‘‘

when you use the module, all it does is create a bunch of variables in your namespace. that's it. that's the whole magic trick. ✨

they're named from $b00000000 to $b11111111, and their values are the corresponding characters. one variable per possible byte. slay.

NB bestie, listen: when you're 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. 🚨 this one matters. don't let the unicode gremlins in.

πŸ¦‹ SOURCE CODE REPOSITORY πŸ¦‹

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

go forth, star it, it's iconic. ⭐


πŸ› BUGS πŸ›

bug reports and requests for extra features should be made on Github. yes, that Github, the repo right above. πŸ‘†


πŸ’– AUTHOR πŸ’–

David Cantrell <david@cantrell.org.uk>


Copyright (c) 2020 David Cantrell.

this program is free software; you can redistribute it and/or modify it under the terms of the Artistic Licence or the GNU General Public Licence version 2, the full text of which is included in this distribution, in the files ARTISTIC.txt and GPL2.txt. πŸ“œ two licences, your pick, no stress, we're generous like that.


🌸 SEE ALSO 🌸

  • perlop's section on quote and quote-like operators 🧚

and that's the page!! πŸŽ€ this was perl v5.36.0, dated 2023-11-18, and honestly? it ate. go interpolate some bytes, bestie, you've got this. πŸ’œβœ¨πŸ¦‹

πŸ“¦ where this page comes from