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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fileparse help

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hi,

I need some quick help with a Perl program that I didn't write that I have to debug. Here is the statement...

Assume $file = myfile.txt.2105

($name, $path, $id) = fileparse($file, '\.2|.0\d+');

When it gets to fileparse, here are the results...

name=myfile.txt.2
path=./
id=105

The problem is that I need it to consider 2105 as the id, not just 105.

My thought is that the '\.2|.0\' part means, any suffix starting with a ".2" or ".0" and that \d+ means find any number of digits after that.

So, what's wrong?

Thanks.

-Tyler
 
The problem is that you're actually saying that the extension is either ".2" or something matching "\.0\d+". You need to group your or.

[tt]fileparse($file, '(\.2|\.0)\d+');[/tt]
 
Ah - thank you so much! That did it!

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top