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