Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Creating Variables Just to Pass into Subroutine?

by jeffa (Bishop)
on Jul 21, 2015 at 21:37 UTC ( [id://1135720]=note: print w/replies, xml ) Need Help??


in reply to Creating Variables Just to Pass into Subroutine?

Since your job is to refactor, i recommend using named parameters with defaults:

sub ampNotify { my %args = @_; # set defaults $args{severity} = defined $args{severity} ? $args{severity} : 3; $args{othercontact} ||= 'None'; .... }

And then you can call like so:

ampNotify( message => join( "\n", "Server: $server", "File: $origfile", "Erro +r: foo" ), subject => "Error processing $filename", who => 'su_and_it', path => $work_dir, file => $missingdeptfilename, );

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Creating Variables Just to Pass into Subroutine?
by mdskrzypczyk (Novice) on Jul 22, 2015 at 13:42 UTC
    While I do agree that the calling of the function gets cleaned up a lot, I fear that it adds complexity to the function definition that the team in my department may have trouble understanding further down the road. I know I said I need to refactor but I'm also trying to make the code a little more intuitive for the people that don't really get perl that much, is there a way to consolidate the two?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-28 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found