Saturday, March 14, 2009

Read command line arguments in perl script

Somehow, I never got it right in first attempt and hence keeping a note here.

use strict;
use Getopt::Std;
use vars qw ($opt_d $opt_p $opt_r $opt_m $opt_t $opt_a);
getopts('d:p:r:m:t:a:') ;
$Depot = $opt_d;
$Product = $opt_p;
$Release = $opt_r;
$Branch = $opt_m;
$BuildTimeStamp = $opt_t;
$Action = $opt_a;
print ("Depot == $Depot");

The most important code to note is "use vars qw" declaration for opt_? kind of variables.

No comments: