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 @_;


>    for (@$thing1) # to access the whole array after referencing
>
for clarity use: for (@{$thing1}){...}

>    {
>        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)];

> foo(\@array); # pass @array by reference to sub foo
>
 foo ($array);

your comments are ok, and may I say you should check out
perlreftut by typing  * perldoc perlreftut * on your terminal [without the
stars], and if you will prefer to read the short tutorial as html file,
then you can type this on your terminal:
perldoc -oHTML -dreftutorial.html perlreftut
I believe this will help out alot.

>
> It's pretty confusing, especially since BP uses prototypes during the
> example, which I'm told are bad? Never use them?
>

Please, you can take time out to check on these links:

http://docstore.mik.ua/orelly/perl/prog3/ch06_04.htm,
http://docstore.mik.ua/orelly/perl/cookbook/ch10_12.htm ,
https://www.socialtext.net/perl5/prototype,
http://www.modernperlbooks.com/mt/2009/08/the-problem-with-prototypes.html

-- 
Tim

Reply via email to