thepler has asked for the wisdom of the Perl Monks concerning the following question:
I keep running into this. I have a Path::Class object and I want the "last part" of it. So for:
/my/path/some_dir/ /my/path/some_file.txtI want to get "some_dir" or "some_file.txt" respectively. If my object is a Path::Class::File object, I can call ->basename. If it's a Path::Class::Dir, I can call ->dir_list(-1). What if I don't want to know/care whether it's a ::File or ::Dir? Sure I can do:
but it seems like there should be something simpler. Or something like that should be available as a method on Path::Class::Entity (the superclass of ::File and ::Dir).my $last_part = $p->is_dir ? $p->dir_list(-1) : $p->basename;
Thanks for any thoughts.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: get the "last part" of a Path::Class object
by moritz (Cardinal) on Jun 22, 2007 at 20:33 UTC | |
by Anonymous Monk on Jun 23, 2007 at 07:25 UTC | |
|
Re: get the "last part" of a Path::Class object
by holli (Abbot) on Jun 23, 2007 at 00:57 UTC | |
|
Re: get the "last part" of a Path::Class object
by Anonymous Monk on Jun 23, 2007 at 01:51 UTC | |
|
Re: get the "last part" of a Path::Class object
by mrpeabody (Friar) on Jun 23, 2007 at 19:44 UTC | |
|
Re: get the "last part" of a Path::Class object
by naikonta (Curate) on Jun 25, 2007 at 01:25 UTC |