[Za-pm] GetOpt::Long problem
Jim Keenan
jkeen at verizon.net
Thu Apr 21 05:44:28 PDT 2005
>From: "Olivier, Wim W" <Wim.Olivier at standardbank.co.za>
>Date: Thu Apr 21 04:26:00 CDT 2005
>To: "'za-pm at pm.org'" <za-pm at pm.org>
>Subject: [Za-pm] GetOpt::Long problem
>Hi guys,
>
>Can anyone assist and see the problem I've got here please?
>
>
>I used the method below (local @ARGV = @_;) to get the values of @_ into
>@ARGV for the use of Getopt::Long. It appears to be working fine like that.
At the risk of being accused of not answering your question, I feel compelled to ask: Why are you taking such an unnecessarily convoluted approach to passing arguments to a subroutine? Instead of:
notify_email -r user1 at a.com -r user2 at b.com -s "Subject line" -b "Message body"
... why can't you use a single hash reference like this:
@recipients = qw| user1 at a.com user2 at b.com |;
notify_email( {
recipients => \@recipients,
subject => "Subject line",
body => "Message body",
} );
IMHO, it's a much cleaner interface. It dispenses with the need for the Getopts module. And because with hashes (unlike arrays or Getopts), you don't have to worry about the *order* in which arguments are passed to a subroutine, this interface can flexibly handle future modifications. Just add an additional element to the anonymous hash.
HTH
Jim Keenan
More information about the Za-pm
mailing list