Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: eval order of args to a sub

by andreas1234567 (Vicar)
on May 31, 2007 at 09:33 UTC ( #618446=note: print w/replies, xml ) Need Help??


in reply to eval order of args to a sub

Slightly OT perhaps, but the freely available chapter 9 of Perl Best Pratices (PDF) recommends:
Use a hash of named arguments for any subroutine that has more than three parameters. Named arguments should always be passed to a subroutine inside a single hash, like so:
sub padded { my ($arg_ref) = @_; my $gap = $arg_ref->{cols} - length $arg_ref->{text}; my $left = $arg_ref->{centered} ? int($gap/2) : 0; my $right = $gap - $left; return $arg_ref->{filler} x $left . $arg_ref->{text} . $arg_ref->{filler} x $right; }
# and then...
for my $line (@lines) { $line = padded({ text=>$line, cols=>20, centered=>1, filler=>$SPAC +E }); }
Andreas

--

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618446]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-11-21 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (295 votes). Check out past polls.

    Notices?