Scalar::Readonly(3pm)
β¨ Scalar::Readonly β¨
okay so bestie, this is a whole manual page for Scalar::Readonly, aka the little Perl module that does exactly one thing and does it slayfully: it hands you functions for controlling whether any scalar variable is read-only. that's it. that's the whole name. π
π SYNOPSIS π
like, here's the vibe in code form:
use Scalar::Readonly ':all';
my $foo = "foo";
readonly_on($foo);
$foo = "bar"; #ERROR!
if (readonly($foo)) {
readonly_off($foo);
}
readonly_off($]);
$] = "6.0";
print "This is Perl v$]";
see that #ERROR!? yeah. no cap. she said no to that assignment. π
π DESCRIPTION π
this module is simple. like, deliberately simple. it can make scalars read-only, which is genuinely useful if you've got config variables you want to protect from your own future self at 3am. π«Ά
and here's the unhinged part: this module can also be used to subvert Perl's many read-only variables to potential evil trickery. yes, really. it said that. iconic behavior honestly. π
πΈ readonly
this function takes a scalar variable and tells you whether it is read-only.
- returns
0if the scalar isn't read-only π - returns a positive number if it is β
πΈ readonly_on
makes the passed scalar variable read-only. and if you then try to modify a read-only scalar, your code will die with this exact error message:
Modification of a read-only value attempted at
periodt. your program is done. it said what it said. π
πΈ readonly_off
makes the passed scalar variable read-write. π«
bestie listen β you can even do this to read-only special variables, but you almost certainly don't want to do that. like, almost certainly. i'm just the messenger. π
π¦ EXPORT π¦
':all'=>readonly,readonly_on,readonly_off
π SEE ALSO π
Scalar::UtilAttribute::ConstantConst::Fast
go read those too, they're the friend group. π
π AUTHOR π
Philippe M. Chiasson, <gozer@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright (C) 2004 by Philippe M. Chiasson
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, babe π this was perl v5.42.3, dated 2026-08-19, and it's the Scalar::Readonly(3pm) manual β go make some scalars immutable and stay hydrated πβ¨
π¦ where this page comes from
- ubuntu stonking: libscalar-readonly-perl 0.03-2build4 Β· Artistic-1.0-Perl OR 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