From: "Richard Lee"
one more question on reference,
if say you have sub as below
my @arrayref;
sub do_something {
my $something = @_;
open FILE, "$something", or die;
while (<FILE>) {
my @array = map (split /,/)[1,2,3,5];
push @arrayref, [EMAIL PROTECTED];
}
close FILE;
}
my @arrayref_copy = do_something($something);
Let's for a moment forget about my inefficient style and just look at the
last step.
If I wanted to use @arrayref_copy and pass it into another
subroutine,should I reference them again?(if file itself was pretty big?)
another_sub([EMAIL PROTECTED]); <-- is this the right thing to do? or is
this redundant since array is already collection of reference?
sub another_sub {
}
You are confusing the difference between an array (of array refs) and an
array ref that itself refers to mutiple array refs.
my $aref = [ [1,2], [3,4], [5,6] ];
Now, to dereference the values, you might say
my $value = $aref->[0][1];
Whereas, with an array of arrayrefs, you might
have something like this.
my @array = ([1,2], [3,4], [5,6]);
my $value = $array[0][1];
perldoc perllol explains Perl data structures: arrays of arrays
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/