I have written a module below to handle named parameters. Perhaps you will find it useful.

package NAB::Utils::NP; use strict; use Data::Dumper; use CGI::Util qw/ rearrange /; our $Q; our $VERSION = "1.00"; sub new { my $class = shift; if (!defined $Q) { $Q = { ALIAS => caller(0) }; bless($Q, $class); } return $Q; } sub named_param { my($self, $seq, @p) = self_or_default(@_); my($s, @r) = self_or_default(@p); return rearrange($seq, @r); } sub self_or_default { my $class = $Q; if (defined $_[0] && (! ref $_[0] && ($_[0] eq ref $class || $_[0] eq $Q->{ALIAS}))) { return @_; } return @_ if (ref $_[0] eq ref $class || ref $_[0] eq $Q->{ALIAS}); unless (defined($_[0]) && (ref($_[0]) eq $class || UNIVERSAL::isa($_[0], $class))) { unshift(@_,$Q); } return wantarray ? @_ : $Q; } 1;
__END__ =pod =head1 NAME NAB::Utils::NP - Named Parameter Handling =head1 SYNOPSIS use NAB::Utils::NP; $np = NAB::Utils::NP->new(__PACKAGE__); sub test { my($option1,$option2,$option3) = $np->named_param( [qw/ OPTION1 OPTION2 OPTION3 /], @_); ... } test( -option1=>'a', -option3=>'c' ); __PACKAGE__->test( -option1=>'a', -option3=>'c' ); =cut

And in your application -
use strict; use warnings; use NAB::Utils::NP; my $np = NAB::Utils::NP->new; test( -option1=>undef, -option3=>'c' ); test( 'a', 'b', 'c' ); __PACKAGE__->test( -option1=>'a', -option3=>'c' ); __PACKAGE__->test( 'a', 'b', 'c' ); sub test { my($option1,$option2,$option3) = $np->named_param( [qw/ OPTION1 OPTION2 OPTION3 /], @_); print <<OPTIONS \$option1=$option1 \$option2=$option2 \$option3=$option3 OPTIONS ; }
And the output -
$option1= $option2= $option3=c $option1=a $option2=b $option3=c $option1=a $option2= $option3=c $option1=a $option2=b $option3=c

In reply to Re: Strange behaviour - cgi related by Roger
in thread Strange behaviour - cgi related by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.