Reputation: 141
I have a string:
$path='/home/usr/project/name'
I am trying to use the substitution function to parse the string and get just the name. My desired outcome is:
$path=name
I tried using with no success:
$path =~ s/^.+\///;
I'm not sure if the syntax is correct. Any help would be appreciated.
Upvotes: 1
Views: 83
Reputation: 62037
File::Basename is a more portable solution than using s///
:
use warnings;
use strict;
use File::Basename qw(basename);
my $path = '/home/usr/project/name';
$path = basename($path);
print $path, "\n";
Output:
name
Upvotes: 6