http://qs1969.pair.com?node_id=11145039


in reply to Deferring variables

Hello Chuma,

> number of parameters that can be set by the user

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.

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

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'} // $de +faults{'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 };

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.