Scalar::Readonly(3pm)

πŸ“¦
version 0.03 Β· 5 versions
, in ubuntu stonking

✨ 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 0 if 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::Util
  • Attribute::Constant
  • Const::Fast

go read those too, they're the friend group. πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Philippe M. Chiasson, <gozer@cpan.org>


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