note
Discipulus
Hello [Chuma],<P>
<I>> number of parameters that can be set by the user</I><P>
maybe I'm confused by your post but, if I understand it correctly, you are handling user provided params, if so I'd go totally other way: set defaults, overwrite them with user provided values, validate evrything with your own logic.<P>
Then in the rest of your program you can safely use just one variable with the right name because it was a default or user provided or set by you following your logic<P>
<c>
use 5.0010;
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
# provide sane defaults
my %defaults = (
'margin-left' => undef,
'margin-horizontal' => undef,
'margin' => 5,
);
# use then user provided parameters
unless ( GetOptions (
'margin-left=i' => \$defaults{'margin-left'},
'margin-horizontal=i' => \$defaults{'margin-horizontal'},
'margin=i' => \$defaults{'margin'},
)) {die "$0 usage..."}
# validate them once for all
validate_parameters();
print Dumper \%defaults;
sub validate_parameters{
# here the logic of precedence for all paramenters
$defaults{'margin-left'} //= $defaults{'margin-horizontal'} // $defaults{'margin'};
}
__END__
io@COMP:C>perl params.pl
$VAR1 = {
'margin-horizontal' => undef,
'margin' => 5,
'margin-left' => 5
};
io@COMP:C>perl params.pl --margin-left 33
$VAR1 = {
'margin-horizontal' => undef,
'margin-left' => 33,
'margin' => 5
};
io@COMP:C>perl params.pl --margin-horizontal 4242
$VAR1 = {
'margin-horizontal' => 4242,
'margin-left' => 4242,
'margin' => 5
};
</c><P>
L*<P>
<div class="pmsig"><div class="pmsig-174111">
There are no rules, there are no thumbs..<BR>
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
</div></div><!-- Wiki2Monks {"version":1.161} -->
11145036
11145036