How?? Didn't I pass a reference?That you did, but you also copied the contents of the array that reference pointed to into a new array, which as you can guess, isn't going to effect the array that said reference is pointing to. Here's what you really want
It might be a good idea to learn more about references and how they work in perl. See. perlreftut, perlref, perldsc and tye's References quick reference for further information.use warnings; use strict; my @a = ("a", "b", "c"); Foo(\@a); print "$_ " foreach(@a); sub Foo { my $refA = shift; ## dereference the array $refA->[0] = "hello"; $refA->[1] = "world"; $refA->[2] = "Perl"; } __output__ hello world Perl
_________
broquaint
In reply to Re: Changing items of an array in a function
by broquaint
in thread Changing items of an array in a function
by abhishes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |