Jump to content

Perl Programming/Keywords/ref

From Wikibooks, open books for an open world
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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:

Type Notes
ARRAY reference to an array
CODE
FORMAT
GLOB
HASH reference to a hash
IO
LVALUE reference to an lvalue that is not a variable
REF reference to a reference
Regexp regular expression resulting from qr//
SCALAR reference 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