Hi,
I'm new to Perl and so I'm just starting to understand its power. I'm trying to run a perl script so that users can call it and pass certain arguments in. e.g. ascript -d db1 -i inst1 or ascript -ddb1 -i inst1
My solution is okay but as I'm trying to get a feel of perl I'm guessing there is a better way. ( A case of right answer but probably not best perl solution). I'm after advice really and getting into the perl programmers frame of mind rather than a C developer.
... cut ...
my $str_arg = join " ",@ARGV;
#remove spaces
$str_arg =~ s/\s//g;
@args= split /-/, $str_arg;
shift @args;
for my $arg (@args)
{
my $opt = substr($arg,0,1);
switch ($opt)
{
case /d/
{
#this is taking the value off.
$options{$opt}=$arg;
print "This is a database $options{$opt}\n";
}
case /i/
{
$options{$opt}=$arg;
print "This is an instance $options{$opt}\n";
}
else
{
print "Error arg not recognised!!!\n";
}
}
}
Thanks,
DanDan
Thanks for all your great help... The solutions and ideas and pointers are spot on.
Thanks,
DanDan.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.