[Pdx-pm] last directory in a path

Thomas Keller kellert at ohsu.edu
Thu Nov 8 10:06:45 PST 2007


In case anyone else falls into this little trap:

The problem I had with both basename and splitdir methods was the  
trailing slash:
(though I admit to being to hurried and/or lazy to read the whole  
perldoc file)

kellert$ perl filemethods.pls /Users/kellert/Documents/Computing/Logs/

Path given as argument: /Users/kellert/Documents/Computing/Logs/
splitdir method:
basename method:

kellert$ perl filemethods.pls /Users/kellert/Documents/Computing/Logs

Path given as argument: /Users/kellert/Documents/Computing/Logs
splitdir method: Logs
basename method: Logs


thanks,

Tom
MMI Shared Resource Facility
503-494-2442
kellert at ohsu.edu



On Nov 8, 2007, at 9:54 AM, James W. Abendschan wrote:

> On Thu, 8 Nov 2007, Thomas Keller wrote:
>
>> Thanks.
>> But for some reason I get the following when I try to use basename:
>> "Can't locate object method "basename" via package "File::Spec" at
>> filespec_methods.pls line 13."
>
> basename is imported from File::Basename, not File::Spec -- so
> this ought to work:
>
>  #!/usr/bin/perl
>
>  use File::Basename;
>
>  print basename("/Users/me/data/this_one/") . "\n";
>
> James
>
>



More information about the Pdx-pm-list mailing list