I think you can just pass the object to File::Spec::splitpath() function because the class implements string overloading method. So, you don't have to care whether what you pass is ::File or ::Dir object.$ perl -MFile::Spec -wle 'my $path = shift; my $last = (File::Spec->sp +litpath($path))[-1]; print $last' /etc/httpd/conf conf $ perl -MFile::Spec -wle 'my $path = shift; my $last = (File::Spec->sp +litpath($path))[-1]; print $last' /etc/httpd/conf/httpd.conf httpd.conf
Of course, you still have to know what object you want to create in the first place.$ perl -MPath::Class -wle 'my $path = shift; my $obj = file($path); pr +int +(File::Spec->splitpath($obj))[-1]' /etc/httpd/conf/httpd.conf httpd.conf $ perl -MPath::Class -wle 'my $path = shift; my $obj = dir($path); pri +nt +(File::Spec->splitpath($obj))[-1]' /etc/httpd/conf conf
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
In reply to Re: get the "last part" of a Path::Class object
by naikonta
in thread get the "last part" of a Path::Class object
by thepler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |