>I took a look on www.perldoc.com and checked out "split". I can't figure out how to 
>do it from the examples?

>Help?

Try out the following piece of code :

************************
use File::Spec;
use strict;

my $test = "C:\\temp\\test\\filename";
my ($volume,$directories,$file) = File::Spec->splitpath( $test );

print $volume, "\n";
print $directories, "\n";
print $file, "\n";
*************************

The thing to keep in mind is that the back slash needs to be escaped. 
Hence if you are getting the path from an external source, it would be a 
good idea to first convert all backslashes to forward slash and then do the 
split.  

************************
use File::Spec;
use strict;

my $test = "C:\\temp\\test\\filename";
$test =~ s/\\/\//g;

my ($volume,$directories,$file) = File::Spec->splitpath( $test );

print $volume, "\n";
print $directories, "\n";
print $file, "\n";
******************




On Thu, 01 Aug 2002 11:48:22 -0400, FlashGuy wrote:

> 
> You mean "split"?
> 
> On 01 Aug 2002 11:41:51 -0400, Robin Norwood wrote:
> 
> > "FlashGuy" <[EMAIL PROTECTED]> writes:
> > 
> > > Hi all,
> > > 
> > > I have the following line in my Perl script
> > > 
> > > $test=$ARGV[0] which dumps the following results
> > > 
> > > =D:\temp\test\filename
> > > 
> > > I need to extract only the "filename" to the right of the last "\" and put that 
>into a variable.
> > > There could only be one "\" in the path or possibly more. This will vary based 
>on directory structure.
> > > 
> > > How would I go about this?
> > 
> > use File::Spec->splitpath - 
> > 
> > Look for 'splitpath' in `perldoc File::Spec` or `perldoc File::Spec::Win32`
> > 
> > -RN
> > 
> > -- 
> > 
> > Robin Norwood
> > Red Hat, Inc.
> > 
> > "The Sage does nothing, yet nothing remains undone."
> > -Lao Tzu, Te Tao Ching
> 
> 
> 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to