--On Wednesday, September 03, 2003 9:20 PM -0600 [EMAIL PROTECTED] wrote:
On Mon, 1 Sep 2003 [EMAIL PROTECTED] wrote:
What is the function of cutting a string from a point until the last character?
For example $string="C:/progra~1/directory1/directory2/file.txt";
i want to find the last backslash (/) of the string and keep the sequence following it (file.txt)
Is it simple?
I tried with the split function but it returns a list.
Well, that's what split() does. :-)
#> my $test1='';I just want a scalar!
why not try this?
# !/usr/bin/perl my @test='';
my $string = "C:/test/me"; @test = split('/',$string); print "@test\n"; print "$test[$#test]\n";
Easier (IMO) and portable:
use File::Basename; my $string="C:/progra~1/directory1/directory2/file.txt"; my $file = basename $string;
Then you don't need to worry about the directory separator, e.g.;
use File::Basename; my @p = ( "C:/progra~1/directory1/directory2/file.txt", 'C:\progra~1\directory1\directory2\file.txt', "C:\\progra~1\\directory1\\directory2\\file.txt", "C:/progra~1\\directory1\\directory2/file.txt" ); print basename($_), "\n" for @p;
prints 'file.txt' four times.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]