Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: passing arrays to subroutines

by gopalr (Priest)
on Mar 16, 2005 at 13:13 UTC ( #439931=note: print w/ replies, xml ) Need Help??


in reply to passing arrays to subroutines

@arr=('1', '2', '3'); test(\@arr); sub test { my $a=@_[0]; print "\n@$a"; }


Comment on Re: passing arrays to subroutines
Download Code
Re^2: passing arrays to subroutines
by nobull (Friar) on Mar 16, 2005 at 21:02 UTC
    my $a=@_[0];

    Unpacking @_ with explicit subscripts is inefficient and unsightly. Using an array slice in a scalar context is also messy.

    my ($a)=@_;
    or
    my $a=shift;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://439931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-07-05 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls