timothy adigun wrote:
Hi Mike D,
Some comments on your codes:
Mike D<ekimduna...@gmail.com> wrote:
Considering the following code, are all my comments correct?
# this function expects an array to be passed by reference
sub foo
{
my ($thing1) = @_; # make a lexical variable for the array being passed
Fine, but since you are getting a reference, I don't really think you need
the "()"
around $thing1, which gives a list context, with one element.
Better put:
my $thing1=shift @_;
TIMTOWTDI
my $thing1 = $_[ 0 ];
for (@$thing1) # to access the whole array after referencing
for clarity use: for (@{$thing1}){...}
TIMTOWTDI
{
print $_."\n";
}
print $thing1->[0]."\n"; # access single element in referenced array
}
my @array = (1,2,3,4);
my $array=[qw(1 2 3 4)];
TIMTOWTDI
foo(\@array); # pass @array by reference to sub foo
foo ($array);
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/