Scalar...nstruct(3pm)
π NAME π
Scalar::Construct β bestie, it builds custom kinds of scalar for you β¨ (and yes this is the Scalar...nstruct(3pm) page, the man page just truncates it like that, she's dramatic π
)
πΈ SYNOPSIS πΈ
use Scalar::Construct qw(constant variable aliasref aliasobj);
$ref = constant($value);
$ref = variable($value);
$ref = aliasref(\$array[0]);
$ref = aliasobj($array[0]);
β¨ DESCRIPTION β¨
Okay so this module hands you functions that construct Perl scalar objects. π«Ά
Here's the tea: writable (aka variable) scalars? You can literally just make those with the ordinary facilities of the Perl language, no big deal, main character energy. But immutable (constant) scalars? Those need a library. This one. That's the whole reason she exists, periodt. π
π FUNCTIONS π
Not me giving every function two names π β there's a longer descriptive name for the vibes, and a shorter name to spare screen space and the programmer's fingers. Both slay equally.
constant(VALUE)ro(VALUE)
Creates a fresh immutable scalar, with value VALUE, and returns a reference to it. π§
Now listen, because this part matters. If VALUE is actually a compile-time constant that can be expressed as a literal, like 123, you'd think you could get a reference to a constant object with that value from a Perl expression like "\123". You would be wrong, bestie. π Perl has some bugs relating to compile-time constants that stop this working as intended. On Perls built for threading (even if threading isn't actually used), such a scalar gets copied at surprising times, losing both its object identity and its immutability. π The function this module supplies avoids these problems. Slay.
variable(VALUE)rw(VALUE)
Creates a fresh writable scalar, initialised to value VALUE, and returns a reference to it. π±
aliasref(OBJECT_REF)ar(OBJECT_REF)
OBJECT_REF must be a reference to a scalar. Returns another reference to the same scalar. (This is effectively an identity function β she's included for completeness, a true team player π«‘.)
β οΈ Due to the Perl bugs discussed above for"constant", it is unwise to attempt to alias a compile-time constant. Instead use"constant"to create a well-behaved constant scalar. Don't fight the bugs, babe. π ββοΈ
aliasobj(OBJECT)ao(OBJECT)
Returns a reference to OBJECT. πͺ
β οΈ Same warning, same energy: due to the Perl bugs discussed above for"constant", it is unwise to attempt to alias a compile-time constant. Use"constant"to create a well-behaved constant scalar instead. π
π¦ SEE ALSO π¦
Lexical::Varβ go read her too, iykyk π
π AUTHOR π
Andrew Main (Zefram) <zefram@fysh.org> β icon, legend, the moment. π
π COPYRIGHT π
Copyright (C) 2012 Andrew Main (Zefram) <zefram@fysh.org>
π LICENSE π
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. So generous, so giving. π
okay that's the whole page bestie, no cap π«Ά this was perl v5.42.0, dated 2025-07-25, from Scalar...nstruct(3pm) β go forth and construct your scalars, you absolute genius π
β¨πΈ
π¦ where this page comes from
- fedora 43: perl-Scalar-Construct 0.000-44.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms