Hi Eventual, On Sat, 7 Sep 2013 04:11:06 -0700 (PDT) eventual <eventualde...@yahoo.com> wrote:
> Hi, > > In the example below, how do I pass @pets and @numbers into the subroutine so > that @animals = @pets and > @digits = @numbers. Please look into references and pass the arrays as references. See: http://perl-begin.org/topics/references/ (NOTE: perl-begin.org is a site I originated and still maintain.). Some comments about your code: > Thanks > > my @pets = ('dogs' , 'cats' , 'horses'); > my @numbers = (1..10); > > &study (@pets , @numbers); 1. There's already a built-in function called study so please pick another name: http://perldoc.perl.org/functions/study.html 2. Please don't call subroutines with ampersands ("&"): http://perl-begin.org/tutorials/bad-elements/#ampersand-in-subroutine-calls > > sub study { > > my (@animals, @digits) = (@_[0] , @_[1]); 1. Don't subscript arrays using @array[$idx]: http://perl-begin.org/tutorials/bad-elements/#at-array-for-subscripting 2. Don't use positional arguments: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments 3. Assigning to two arrays will cause the first array to swallow all the elements. Use references. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ http://www.shlomifish.org/humour/bits/Can-I-SCO-Now/ - "Can I SCO Now?" Buffy Summers does not really need stakes to slay vampires, because her kisses are deadly for them. And that includes those that she blows in the air. — http://www.shlomifish.org/humour/bits/facts/Buffy/ 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/