Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

See also: ref, reftype

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.

See also: weaken, unweaken

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.

See also: reftype, blessed

reftype

Returns the underlying type of the reference (SCALAR, ARRAY, HASH, CODE, GLOB, REF) without regard to blessing. Returns undef for non-references.

See also: blessed, ref

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.

See also: weaken, isweak

weaken

Weakens a reference so it does not prevent garbage collection of the referent. The reference will become undef when the referent is destroyed.

See also: unweaken, isweak