Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing arguements

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
Help...

I've got a script which I'm passing several arguements to, or maybe none depending on the situation.

I use the join command to smack them into one variable and am working with that.

-snip-

if ($usern =~ m/-[vV]/) { # verbose
$usern =~ s/\s*(\-[vV])\s*//;
$v = 1;}

if ($usern =~ m/-[dD]/) { # duplicates
$usern =~ s/\s*(\-[dD])\s*//;
$d = 1;}

if ($usern =~ m/-[fF]/) { # filename
$usern =~ s/\s*(\-[fF])\s*//;}

-unsnip-

This last one is where I'm stuck. What I was doing before was assuming that the remaining data in the string was the filename. What I would rather do is grab everything from after the -f excluding the first space to the end or next space whichever it finds first.

There may well be a better way to do all of this, but this is what I came up with so far =)

Thanks
 
Hmm, still no help =
I've fuddled with a few options and I'm still stuck. maybe I didnt leave enough information.

I should add that this is what I'm doing with the argv
my $usern = join ' ', @ARGV;

a sample line of input might be:

perl test.pl -v -f filename.txt
or
perl test.pl -d -f filename.txt
or
perl test.pl -v -d -f filename.txt

The I get everything so far except the actual filename. I've even gotten that except for the extension (thought I could use w+ but it stopped at the dot.).

Thanks in advance for any help.
 
try to use $1 instead of using the s///
if ($usern =~ m/-[fF] (\w+\.?\w*)/) { # filename
$filename = $1;
}

$1 ($2, $3,...) contains everything what is between the first(second third) ()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top