Ben -
You can use the File::Basename module for this:
Your program would be akin to:
foreach $line (@Path_Filename)
{
chomp($line);
$filename = basename($line); # gives you the filename with the
extension
$location = dirname($line); # gives you the location with no
trailing /
}
Here are some examples:
~% perl -MFile::Basename -e'print basename($ARGV[0])' /etc/hosts.equiv
hosts.equiv
~% perl -MFile::Basename -e'print dirname($ARGV[0])' /etc/hosts.equiv
/etc
~ Jess
> -----Original Message-----
> From: Ben Crane [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, December 10, 2003 9:22 AM
> To: [EMAIL PROTECTED]
> Subject: file path pattern matching problem.
>
>
> Hi all,
>
> I'm trying to split apart a filepath...e.g:
> c:\test\abc\what\somefile.txt
> The length of the filepath will never be constant...
>
> e.g:
> foreach $line (@Path_Filename)
> {
> chomp($line);
> (@Path_Breakdown) = split(/(\w+\W)(\w+\W)/, $line);
> }
>
> but my biggest problem is how to match a word
> character \w then match everything until the last
> \...that will comprise of the file path and the final
> \ onwards will be the filename incl. or excl. the file
> extension...
>
> I've tried to get the pattern matching to include
> everything including the \ but it doesn't seem to
> work. The closest I've gotten is:
>
> c:\test\abc\what\somefile.txt
> c:
> \test\abc\what\
> somefile.
> txt
>
> Any ideas? Is there a pattern character that I'm
> missing here that allows you to match a certain
> character and then stop if it's the last one of it's
> type?
>
> Ben
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>