1 2 3 4
use File::Basename; my $string = "/opt/pmg/ptt/book1_test"; my $dirname = dirname($string);
1 2 3 4
my $string = "/opt/pmg/ptt/book1_test"; my @path = split /\//,$string; delete @path[-1]; my $path = join '/',@path;
1 2 3
my $string = "/opt/pmg/ptt/book1_test"; my ($path) = ($string =~ m|^(/.+/)|); print $path;
1 2
my $string = "/opt/pmg/ptt/book1_test"; my ($path) = ($string =~ m|^(/.+/book)|);
1
2
3
4
my $string = "/opt/pmg/ptt/book1_test";
my ($path, $name) = ($string =~ m~^(.+/book)(.*)$~);
print $path; # /opt/pmg/ptt/book
print $name; # 1_test
1 2 3 4 5
my $string = "/opt/pmg/ptt/book1_test"; my $path_incl_book; if ( $string =~ / (.* book) /x ) { $path_incl_book = $1; }