A reference is a scalar variable pointing-or refering to-something else : Reference « Data Type « Perl






A reference is a scalar variable pointing-or refering to-something else

   

#To set up a reference, you use a backslash (\) character before the name of what you're referring to.
#$reference = \$referred_to;
#The reference is a scalar variable. 
#To access the value of the data referred to:
#$new_var = ${ $reference };
#You can also use a shorthand syntax like the following: 
#$new_var = $$reference;


#!/usr/bin/perl -w

# Reference to a scalar variable.
$var = "Hello";

$reference = \$var;

print "Scalar reference = $$reference\n\n";

   
    
    
  








Related examples in the same category

1.Perl 5 Dereferencing Operators
2.Perl 5 Reference Assignments
3.Reference is a scalar variable
4.Increments Reference
5.Nested reference
6.References to references
7.References, Pointers
8.Creating and Dereferencing Pointers
9.Creating and dereferencing a reference
10.Creating reference for arrays
11.Demonstrates the reference syntax
12.Dereference pointer
13.Dereferencing a Reference
14.Dereferencing the Pointer
15.Direct Reference Techniques
16.Direct Scalar References
17.Exchange reference
18.Get a reference to a file handle by using '$ioreference = *name{IO};'
19.Get reference of a range
20.Get the reference of the return value from substr
21.Get the reference to a scalar by using the form '$scalarreference = *name{SCALAR};'
22.Get the reference to a subroutine by using the form '$codereference = *name{CODE};'
23.Get the value from a reference
24.Reference Modification
25.Using $$ to get the value of the reference