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..

//Dave
-----Original Message-----
From: Jeff AA [mailto:[EMAIL PROTECTED]]
Sent: den 19 september 2002 09:39
To: 'David Samuelsson (PAC)'; [EMAIL PROTECTED]
Subject: RE: Using GetOpt::Long



> -----Original Message-----
> From: David Samuelsson (PAC) 
> [mailto:[EMAIL PROTECTED]] 
> Sent: 19 September 2002 08:09
> To: '[EMAIL PROTECTED]'
> Subject: Using GetOpt::Long
> 
> 
> I found this module was a part off the package, and tried it 
> out, it works as i want. I have some troubles though, i am 
> going to use quite a lot of sub routines in my scrip, how can 
> i define and structure so that the commandline switches will 
> actually be the subs executed?
> 
> for example i have this:
> 
> use Getopt::Long;
> 
> if (!GetOptions("reg_backup" => \$reg_backup,
>                "html"  => \$html)
>    ){err_exit("$usage\n",0);}
> 
> if (defined ($reg_backup) ){reg_backup()}
> if (defined($html)){create_html()}
> etc..
> 
> when i execute the script it does as its told, but if i want 
> to combine the 2 subs, so that it should first run the 
> regbackup sub, (then i have the resul in an array), then it 
> should print that result in the html sub. how should i 
> structure the if statments to accomplish this?

do you want something like this?

use strict;
use English;

# Set Default values
our %opt = (
  reg_backup => 0, # Default is no reg_backup
  html       => 0, # Default is no html
);

# Allow Command Line override of defaults
GetOptions(
  \%opt,
  'reg_backup!',
  'html!',
 ) or die "GetOptions error: $OS_ERROR";

my @result;
@result = reg_backup() if $opt{reg_backup};
create_html( \@result ) if $opt{html};

you can then call your script like this:
  myscript.pl --reg_backup --html
  myscript.pl --noreg_backup --html  
  myscript.pl --reg_backup --nohtml
etc etc

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to