# Create References in Perl

PERLServer Side ProgrammingProgramming Scripts

#### Perl Online Training

46 Lectures 4.5 hours

#### COMPLETE PERL Programming

11 Lectures 1.5 hours

#### Perl for Beginners: Learn A to Z of Perl Scripting Hands-on

30 Lectures 6 hours

A Perl reference is a scalar data type that holds the location of another value which could be scalar, arrays, or hashes. Because of its scalar nature, a reference can be used anywhere, a scalar can be used.

It is easy to create a reference for any variable, subroutine or value by prefixing it with a backslash as follows −

$scalarref = \$foo;
$arrayref = \@ARGV;$hashref = \%ENV;
$coderef = \&handler;$globref = \*foo;

You cannot create a reference on an I/O handle (filehandle or dirhandle) using the backslash operator but a reference to an anonymous array can be created using the square brackets as follows −

$arrayref = [1, 2, ['a', 'b', 'c']]; Similar way you can create a reference to an anonymous hash using the curly brackets as follows − $hashref = {
};
\$coderef = sub { print "Boink!" };