Copyright © tutorialspoint.com

PERL ref Function


Syntax

ref EXPR

ref


Definition and Usage

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.

Return Value

  • Returns in Scalar Context: Empty string if not a reference String if a reference

Example

Try out following example:

#!/usr/bin/perl -w

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

It will produce following results:

ref() $foobar is now in class ATMPCLASS

Copyright © tutorialspoint.com