Hi I need to pass comma seperated arguments to a perl script?
It is like:
Exect.pl -d GUI1,GUI2,GUI3
and I need to store these argsGUI1,GUI2,GUI3 in an array.
can anyone suggest how to do that:
Hi I need to pass comma seperated arguments to a perl script?
It is like:
Exect.pl -d GUI1,GUI2,GUI3
and I need to store these argsGUI1,GUI2,GUI3 in an array.
can anyone suggest how to do that:
The crude way:
#! /usr/bin/perl -w
use strict;
if ( @ARGV != 2 ) {
print "Invalid number of arguments.\n";
exit;
}
my @elements = ();
if ( $ARGV[0] eq "-d" ) {
@elements = split /,/, $ARGV[1];
print "Arguments are: @elements\n";
}
else {
print "Invalid switch. Please try again.\n";
}
You may also take a look at Getopt::Std for a neater implementation.