> -----Original Message-----
> From: David Samuelsson (PAC)
> [mailto:[EMAIL PROTECTED]]
> Sent: 19 September 2002 09:03
> To: 'Jeff AA'; [EMAIL PROTECTED]
> Subject: RE: Using GetOpt::Long
>
>
> I want it so it will execute the subs in the order according
> to the lines when i start the scrippt, and i will try to
> keep to default -value cause the scipt will probably be used
> by others aswell so no double --.
>
> when i run myscript.pl -reg_backup -html
>
> it should execute reg_backup sub first then the html sub. I
> plan to have an exit sub that will run if they havent put the
> switches togheter right. It will be more commnd lines, so if
> they enter it wrong it will die with an error. and off course
> there will be some command line that will run almost all
> subs, but in the order i have specified. So when they specify
> lets say -all switch it goes to $all here is an order off all
> subs and the order it should run them in..
>
in that case don't bother with GetOpts, as it doesn't maintain the order
of the parameters. Try something like this:
use strict;
# This is the default order when no params set
my @funcs = (qw( func1, func2, func3, func4 ));
# Parameters override the defaults
@funcs = @ARGV if @ARGV;
# map the parameter names to the addresses of the subs
my %despatch = (
func1 => \&func1,
func2 => \&func2,
func3 => \&func3,
func4 => \&func4,
);
# Do the funcky stuff in user determined order
my @result;
for my $func ( @funcs ) {
$func = lc($func); # case-insensitive
# Do we have a function that matches the user requested name?
if ( $despatch{$func} ) {
@result = &{$despatch{$func}}( \@result )
} else {
die "Unrecognised function: '$func'";
}
}
then just call
myscript.pl func2 func4 func1
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]