Here is a snippet using Getopt::Long. You can call the script with a "--run_script" argument (or just "-r"-- Getopt::Long accepts unique abbreviations for flags). You could put an if block after the print statement to control which code, depending on the value of $pars{run_script}:
#!/usr/bin/perl use warnings; use strict; use Getopt::Long; my %pars = ( run_script => 0 ); GetOptions ( \%pars, 'run_script=f', ); print "Run script $pars{run_script}\n"; allen94-lt 11: ./getopt_ex.pl -r 5 Run script 5 allen94-lt 12: ./getopt_ex.pl Run script 0
Note the default value (0) that run_script has been given in the creation of the %pars hash. You could change this by changing the original setup of the hash.
--Kester
In reply to Re: Combining two scripts with a command line switch?
by kesterkester
in thread Combining two scripts with a command line switch?
by Seventh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |