Perl ref Function

Advertisements


Description

This function returns a true value if EXPR, or $_ if EXPR is not supplied, is a reference. The actual value returned also defines the type of entity the reference refers to.

The built-in types are:

  • REF

  • SCALAR

  • ARRAY

  • HASH

  • CODE

  • GLOB

  • LVALUE

  • IO::Handle

If a variable was blessed with the bless() function, then the new data type will be returned. The new data type will normally be a class name.

Syntax

Following is the simple syntax for this function:

ref EXPR

ref

Return Value

This function returns empty string if not a reference and string if a reference in Scalar Context.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl -w

$foobar = { };
bless($foobar, 'ATMPCLASS');
print "ref() \$foobar is now in class ", ref($foobar), "\n";

When above code is executed, it produced following result

ref() $foobar is now in class ATMPCLASS


Advertisements
Advertisements