--- Begin Message ---
No, 'split' is a built-in function, which you could also use. The
reason I recommend File::Spec is that it is portable and standard.
Generally, if a cpan module exists which covers your task, I'd use
it. The 'split' method would be:
my $file = (split /\\/, $test)[-1];
Which would work for your case, but would break if (for instance) your
script were used in a Unix environment. Or, say '$test' was not
initialized - you would get a warning with the 'split' version.
The writers of CPAN modules have generally spent a good bit of time
making a module both portable and resistant to 'corner cases'. If
File::Spec is not installed on your system, use CPAN:
http://search.cpan.org/search?mode=module&query=File%3A%3ASpec
Basically, the command would be:
Use File::Spec;
my ($volume,$directories,$file) = File::Spec->splitpath( $test );
But I still recommend that you read over the documentation for it - it
has several other useful functions.
-RN
"FlashGuy" <[EMAIL PROTECTED]> writes:
> 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?
>
> 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
>
>
>
--
Robin Norwood
Red Hat, Inc.
"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
--
Robin Norwood
Red Hat, Inc.
"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
--- End Message ---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]