Scalar::Util
Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.
Provides scalar utility functions (blessed, reftype, etc.)
Synopsis
use Scalar::Util qw(blessed reftype weaken looks_like_number);
if (blessed $obj) {
print ref($obj), "\n";
}
my $type = reftype($ref); # "HASH", "ARRAY", etc.
weaken($ref); # prevent circular reference leak
if (looks_like_number($str)) {
print "$str is numeric\n";
}
Functions
blessed
Returns the package name if the argument is a blessed reference,
undef otherwise.
dualvar
Creates a scalar that has both numeric and string values independently. Currently limited in PetaPerl — returns only the numeric value.
isdual
Returns true if EXPR is a dualvar (has independent numeric and string values). Not implemented in PetaPerl — always returns false.
isvstring
Returns true if EXPR was created as a v-string (v1.2.3).
Not implemented in PetaPerl — always returns false.
isweak
Returns true if REF is a weak reference.
looks_like_number
Returns true if EXPR looks like a number to Perl (integer, float, or scientific notation). Useful for input validation.
openhandle
Returns FH if it is an open filehandle, undef otherwise. Recognizes
STDIN, STDOUT, STDERR and PetaPerl filehandle IDs.
readonly
Returns true if SCALAR is read-only. Currently not implemented in PetaPerl — always returns false.
refaddr
Returns the internal memory address of the referent as a plain integer.
Returns undef for non-references.
reftype
Returns the underlying type of the reference (SCALAR, ARRAY, HASH, CODE,
GLOB, REF) without regard to blessing. Returns undef for non-references.
set_prototype
Sets the prototype of a subroutine at runtime. CODEREF must be a
reference to a subroutine. PROTO is the new prototype string, or
undef to remove the prototype. Returns the coderef.
tainted
Returns true if EXPR is tainted. PetaPerl does not implement taint mode — always returns false.
unweaken
Strengthens a weak reference back to a normal (strong) reference.
weaken
Weakens a reference so it does not prevent garbage collection of the
referent. The reference will become undef when the referent is
destroyed.