in reply to Creating Variables Just to Pass into Subroutine?
You should use my in front of variables and you don't need & to call functions anymore.
To answer your question, the real problem are the many positional parameters you need.
In this case "Throw away" variables help documenting your code and improve readability.
BUT the far better solution would be to pass named arguments.¹
e.g.
ampNotify( who => "su_and_it", subject => "Error processing $filename", severity => 3, othercontact => "None", path => $work_dir, file => $missingdeptfilename, message => <<"__message__"); Server: $server File: $origfile Error: Departments missing from WWMBR_NAMES.TXT __message__
Please note that the use of a here-doc for the message is not essential for this solution, you are also free to write something like
ampNotify( ... message => qq(Server: $server File: $origfile Error: Departments missing from WWMBR_NAMES.TXT), othercontact => "None", ... );
TIMTOWTDI, Perl gives you the freedom to chose the best readable/maintainable form for your team, even an extra $message variable can be a good choice here.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
changed the order of arguments, since Here doc must immediately follow the opening << line.
Thanks to choroba for messaging me. :)
¹) example
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating Variables Just to Pass into Subroutine? (named arguments)
by mdskrzypczyk (Novice) on Jul 22, 2015 at 13:35 UTC | |
by LanX (Saint) on Jul 23, 2015 at 19:10 UTC |