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

ref

Returns the reference type or blessed class name of a value.

Pops one value and pushes a string describing its reference type. For blessed references, returns the class name (e.g. "MyClass"). For unblessed references, returns the underlying type: "SCALAR", "ARRAY", "HASH", "CODE", "REF", "GLOB", or "Regexp". For non-references, returns the empty string "".

Delegates to Sv::ref_type() for the actual type determination.

Synopsis

my $type = ref $ref;           # "HASH", "ARRAY", "SCALAR", "CODE", etc.
my $class = ref $object;       # "MyClass" for blessed references
if (ref $x) { ... }            # true if $x is a reference

Implementation Notes

perl5 (pp.c pp_ref): If blessed, returns class name. Otherwise returns type name (SCALAR, ARRAY, HASH, CODE, REF, GLOB, etc).

See Also

PP runtime: ref | bless, Scalar::Util