in reply to reference array and pass ref to sub
To take a reference, you need
my $arrayref = \@array;
and to dereference it, you write
my @array = @$arrayref; # whole array # or my $elem = $arrayref->[0]; # individual element
In other words, your code should look something like
use warnings; use strict; my @array = (1,2,3,4,5); my $arrayref = \@array; mysub($arrayref); sub mysub { my ($aref) = @_; for my $i (0 .. $#$aref) { print "value of i is:$i \n"; print "Array Value:$aref->[$i] \n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reference array and pass ref to sub
by csarid (Sexton) on Mar 06, 2009 at 22:09 UTC |