Monday, June 27, 2011

Perl dereferencing

Reference in  perl:

$scalarref=\$foo;      # for  storing scalar variable reference
$constref=\182_5555.45    # for  storing constant reference
$arrayref=\@dddd;     # for  storing  array reference
$hashref=\%hash;      # for storing hash reference
$coderef=\&handler;     # for  storing subroutine reference
$globref=\*STDOUT;    # for  storing STDOUT reference
anonymous subroutine composer

$coderef=sub { print "hello!\n"};
$objref=new Doggie Tail=>'short',Ears=>'long';

for deferencing a scalar variable

$foo="two humps";

For deferencing the array 

$arrayref->[0]="January";   # using the arrow operator

For deferencing the hash:

$hashref->{KEY}="VALUE";  #using the arrow operator

For deferencing the sub-routine reference: 


For deferencing the global reference:

print $globalref "output\n";     # prints output to the standard output.

No comments:

Post a Comment