Mike D wrote:
Hi all,

Hello,


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?

They appear to be generally correct.


# this function expects an array to be passed by reference
sub foo
{
     my ($thing1) = @_; # make a lexical variable for the array being passed

Copy the contents of the array @_ to the newly created list my(...), in this case a single element list.


     for (@$thing1) # to access the whole array after referencing

Access the whole array after dereferencing.


     {
         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

British Petroleum?


uses prototypes during the
example, which I'm told are bad? Never use them?

Prototypes in Perl were designed to help replace Perl's built-in functions. They are not really designed for use in users' subroutines.

Perhaps this will help explain:

http://groups.google.com/group/comp.lang.perl.modules/msg/84484de5eb01085b



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/


Reply via email to