Hi all, just started using Perl today, coming over from a background in
C#/Java and Python.
I seem to be grasping Perl rather nicely (I think) until I got up to
references in Beginning Perl.
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
for (@$thing1) # to access the whole array after referencing
{
print $_."\n";
}
print $thing1->[0]."\n"; # access single element in referenced array
}
my @array = (1,2,3,4);
foo(\@array); # pass @array by reference to sub foo
It's pretty confusing, especially since BP uses prototypes during the
example, which I'm told are bad? Never use them?
Thanks!