PerlIO::scalar(3perl)

πŸ’– PerlIO::scalar β€” the 3perl page, but make it make sense πŸ’–

okay so bestie, welcome to PerlIO::scalar, which lives in the Perl Programmers Reference Guide. it's literally in-memory IO β€” scalar IO β€” and it's genuinely one of the cutest little tricks in Perl, no cap. let's get into it πŸ¦‹


✨ NAME ✨

PerlIO::scalar β€” in-memory IO, scalar IO 🫢


✨ SYNOPSIS ✨

okay so here's the vibe. you've got a scalar, right? and you wanna treat it like a file. boom:

my $scalar = '';
...
open my $fh, "<",  \$scalar or die;
open my $fh, ">",  \$scalar or die;
open my $fh, ">>", \$scalar or die;

or, if you're feeling extra and wanna be explicit about it:

my $scalar = '';
...
open my $fh, "<:scalar",  \$scalar or die;
open my $fh, ">:scalar",  \$scalar or die;
open my $fh, ">>:scalar", \$scalar or die;

both slay. the second one is just telling Perl out loud what the first one already figured out πŸ’…


✨ DESCRIPTION ✨

so here's the tea: a filehandle gets opened, but the file operations aren't happening on any actual file on your disk. nope. they're performed "in-memory" on a scalar variable. your scalar is the file. it's giving main character energy πŸŽ€

and the best part? all the normal file operations can be performed on the handle. all of them. read, write, append, whatever you'd do to a real filehandle β€” do it here, it works. no cap.

the scalar itself is considered a stream of bytes. that's the mental model, that's the vibe, that's the whole thing 🧚

⚠️ heads up though: currently fileno($fh) returns -1. so if you were counting on a real file descriptor number... yeah, it's not that kind of party πŸ’€

also important, and I need you to actually read this part bestie: attempting to open a read-only scalar for writing will fail, and if warnings are enabled, it'll produce a warning too. so it fails and snitches on you. rude but fair 😭


✨ IMPLEMENTATION NOTE ✨

PerlIO::scalar only exists as a stub. like, it's there, it's a whole module, it has a name and everything β€” but it's a stub.

the takeaway? you do not need to explicitly use PerlIO::scalar. it's already handled. don't do the extra work, bestie, you're above that 🌸


πŸ’œ SEE ALSO πŸ’œ

nothing listed here, so honestly, go forth and open stuff into scalars. iconic behaviour. periodt πŸ‘‘


okay that's the whole page, you're welcome, you're a Unix girlie now πŸ’– this was the PerlIO::scalar page, 3perl edition, straight outta perl v5.44.0, dated 2026-10-17 β€” so go be iconic with your in-memory IO and remember: the filehandle is fake but the rizz is real πŸ¦‹πŸ’…


πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms