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!

regex & path problem...

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
I have a program which can require several arguements. I use the join command then parse out data I recognize.

the scrip snip below is what I use to grab the filename. I'm not sure why it won't accept full pathing such as "D:\utility\filename.txt" which comes out as just "D"

if ($input =~ m/-[oO] (\w+\.?\w*)/) { # fileout
$fileout = $1;
$input =~ s/\s*(\-[oO])\s*//;
$input =~ s/$fileout//i;
print "Fileout: $fileout\n";
open (OUT,">$fileout") || die "can't open $fileout: $!";
$o = 1;
select OUT;
}


As I look at this, I'm thinking that the word boundaries are defined as only alpha characters?
 
The reason is because [tt]:[/tt] and [tt]\[/tt] are not word characters matched by [tt]\w[/tt]. It would be quite complicated to come up with a regex that matches a legal DOS-style file name. (Possible, of course, but is it worth the effort?) Why not just say that everything after whitespace after the -o is part of the filename?

[tt]if ($input =~ /-o\s+(.*)/i) {[/tt]
 
I might try a variation on that, I'm not so great at my Regex's ;) I have several paramaters I pass so I would need to get everything up to the next space which is doable I'm sure =)

Thanks for the tip, I'll try to get that to work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top