in reply to Creating Variables Just to Pass into Subroutine?

> Also, I would greatly appreciate any tips on refactoring perl code in general, methodologies or processes that you may have used before to approach it.

here a way to convert ampNotify to allow named parameters without breaking the old positional interface:

use strict; use warnings; use Data::Dump qw/pp/; sub ampNotify { my ($who ,$subject ,$severity ,$message , $othercontact ,$path ,$f +ile) = @_; # --- this will use named parameters if first arg is hashref if (ref($who) eq "HASH"){ # - defaults (optional) my %defaults = ( who => "su_and_it", severity => 3, othercontact => "None", ); my %args = ( %defaults, %$who); # - parameter check (optional) my @obligatory = qw/subject message path file/; for (@obligatory){ die "missing '$_' argument in ampNotify() " unless exists +$args{$_} } ($who ,$subject ,$severity ,$message , $othercontact ,$path ,$ +file) = @args{qw/who subject severity message othercontact path fil +e/}; } # check content pp [($who ,$subject ,$severity ,$message , $othercontact ,$path ,$ +file)]; # --- your orig code following # ... } # --------- USAGE my $message= <<"__message__"; Server: SERVER File: ORIGFILE Error: Departments missing from WWMBR_NAMES.TXT __message__ ampNotify( { who => "su_and_it", severity => 3, othercontact => "None", path => 'FOO', file => 'BAR', subject => "Error processing 'BAZ' ", message => $message, } );

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re: Creating Variables Just to Pass into Subroutine? (refactoring)
  • Download Code