in reply to User-Defined Sub, Passing a Single Argument?
so that the assignment is in list context. See Context in perldata.sub myFunction { my ($arg) = @_; #blah blah blah, do some stuff..... } myFunction($myArg);
For my own work, I usually use
unless I'm writing an object method, in which case I use shift to get the reference:sub myFunction { my ($arg1, $arg2, ..., $argN) = @_; #blah blah blah, do some stuff..... } myFunction($myArg);
though, if it's just a quick and dirty iterator over a list, sometimes I skip stripping the argument array entirely:sub myFunction { my $self = shift; my ($arg1, $arg2, ..., $argN) = @_; #blah blah blah, do some stuff..... } myFunction($myArg);
See also Best Practices(TM) reference card, noting that it doesn't weigh in.sub myFunction { for (@_) { ... # lvalue; Note this impacts the passed values!! } } myFunction($myArg);
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|