Dereference pointer : Reference « Data Type « Perl






Dereference pointer

   

$age = 25;
@siblings = qw("A", "B", "C","D");
%home = ("owner" => "A",
         "price" => "B",
         "style" => "C",
);

# Create pointer
$pointer1 = \$age;       
$pointer2 = \@siblings;  
$pointer3 = \%home; 
$pointer4 = [ qw(red yellow blue green) ]; # Create anonymous array
$pointer5 = { "A" => "a", "B" => "b", "C" => "c" };
                                           # Create anonymous hash


print $$pointer1; # Dereference pointer to scalar; 
print @$pointer2; # Dereference pointer to array;
print %$pointer3; # Dereference pointer to hash; 
print $pointer2->[1];   
print $pointer3->{"style"}; 
print @{$pointer4}; # prints elements of anonymous array

   
    
    
  








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.Dereferencing a Reference
13.Dereferencing the Pointer
14.Direct Reference Techniques
15.Direct Scalar References
16.Exchange reference
17.Get a reference to a file handle by using '$ioreference = *name{IO};'
18.Get reference of a range
19.Get the reference of the return value from substr
20.Get the reference to a scalar by using the form '$scalarreference = *name{SCALAR};'
21.Get the reference to a subroutine by using the form '$codereference = *name{CODE};'
22.Get the value from a reference
23.A reference is a scalar variable pointing-or refering to-something else
24.Reference Modification
25.Using $$ to get the value of the reference