Perl Programming/Keywords/ref

Previous: redo Keywords Next: rename

The ref keyword

The ref function returns a non-empty string, if EXPRESSION is a reference and an empty string otherwise. Without EXPRESSION, $_ will be used. The returned value depends on the thing referenced to.

ref knows the following types:

TypeNotes
ARRAYreference to an array
CODE
FORMAT
GLOB
HASHreference to a hash
IO
LVALUEreference to an lvalue that is not a variable
REFreference to a reference
Regexpregular expression resulting from qr//
SCALARreference to a scalar
VSTRING

If the referenced object has been blessed into a package, the name of that package is returned instead. This, however, is now considered "bad practice".

Syntax

  ref EXPRESSION
  ref
Previous: redo Keywords Next: rename
Category:Book:Perl Programming#Keywords/ref%20
Category:Book:Perl Programming