denis <[EMAIL PROTECTED]> offered this solution:
: why not try this?
:
: #!/usr/bin/perl
: my @test='';
: my $string = "C:/test/me";
: @test = split('/',$string);
: print "@test\n";
: print "$test[$#test]\n";
The last item of an array can be retrieved
using an index of -1.
print "$test[$#test]\n";
becomes
print "$test[-1]\n";
We don't need an array at all. We can ask split
to return one item:
@test = split('/',$string);
print "$test[-1]\n";
becomes
my $scalar = ( split '/', $string )[-1];
print "$scalar\n";
If we're going to do this a lot, we could write
a sub routine:
print strip_to_end( '/', 'C:/test/me' ), "\n";
sub strip_to_end {
my( $seperator, $string ) = @_;
return ( split $seperator, $string )[-1]
}
Then, if we find a faster method (like 'substr')
we can change the method without effecting the rest
of the program.
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]