On Tue, Jul 05, 2005 at 07:52:13PM +0100, Nick Ing-Simmons wrote: > >I would expect "/var/local/". Instead you get "/var". Normally on Unix > >you can't tell the difference between /foo/dir and /foo/file but the trailing > >slash disambiguates. > > dirname is suposed to mimic what C library/shell does - and on linux: > > [EMAIL PROTECTED]:/home/p4work/mail> dirname /var/local/ > /var > [EMAIL PROTECTED]:/home/p4work/mail> > > Which matches what happens here. > There is also a mountain of legacy code that expects File::Basename > to behave the way it does.
Not being a shell programmer nor a C programmer I expected a function called dirname() to return the directory name and not be some sort of chop fuction for paths. Silly me. In general I find Perl parroting C/Shell mistakes to be... well... a mistake. The mistake is further exasperated when the documentation assumes the reader is already aware of any quirks being parroted. Alas, I've discovered that mountain of legacy code as well and concluded the behavior cannot be changed. So I guess the thing to do is document the dirname() surprise better. In particular, this is a lie: The dirname() routine returns the directory portion of the input file specification. and to realize that its a lie you have to not trust such a simple statement of purpose, wade through the following docs which seem to be only about VMS and Mac portability and have detailed knowledge of how dirname(1) works. In fact the File::Basename docs need a lot of work so I'll be back with a patch. -- Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern 'All anyone gets in a mirror is themselves,' she said. 'But what you gets in a good gumbo is everything.' -- "Witches Abroad" by Terry Prachett