I have a string in a scalar $path , I want to split it to get just the file name. I was splitting on the "/" into an array, and then "popping" the last element of the array into the variable, but is there a simpler way to do this?
Nope. It's a list slice. The "split" function creates a list of scalars. The [-1] indicates that you only want the one on the end. It doesn't affect what "split" is doing at all.
A more standard way of doing this would be to use the "basename" function in the standard File::Basename module, i.e.:
Code:
use File::Basename;
my $path = '/home/ishnid/foo';
print basename( $path ),"\n";
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.