start page | rating of books | rating of authors | reviews | copyrights

Programming Perl

Programming PerlSearch this book
Previous: 3.2.120 redo Chapter 3
Functions
Next: 3.2.122 rename
 

3.2.121 ref

ref 

EXPR

The ref operator returns a true value if EXPR is a reference, the null string otherwise. The value returned depends on the type of thing the reference is a reference to. Built-in types include:

REF SCALAR ARRAY HASH CODE GLOB

If the referenced object has been blessed into a package, then that package name is returned instead. You can think of ref as a "typeof" operator.

if (ref($r) eq "HASH") {     print "r is a reference to a hash.\n"; }  elsif (ref($r) eq "Hump") {     print "r is a reference to a Hump object.\n"; }  elsif (not ref $r) {     print "r is not a reference at all.\n"; }

See Chapter 4 for more details.


Previous: 3.2.120 redo Programming Perl Next: 3.2.122 rename
3.2.120 redo Book Index 3.2.122 rename