Hi Mike, On Thu, 24 Nov 2011 23:28:39 -0500 Mike D <ekimduna...@gmail.com> wrote:
> Hi all, just started using Perl today, coming over from a background in > C#/Java and Python. Welcome to Perl. > > 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? Yes, all your comments appear to be 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? Yes, in general, you shouldn't add prototypes to your subroutines. For more information about references, see the various resources on: http://perl-begin.org/topics/references/ You may also be interested in this page - http://perl-begin.org/tutorials/bad-elements/ , or in the book Modern Perl by chromatic ( http://perl-begin.org/tutorials/modern-perl/ ) which is intended for already experienced programmers. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Rethinking CPAN - http://shlom.in/rethinking-cpan Chuck Norris read the entire English Wikipedia in 24 hours. Twice. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/