in reply to Re: Re: Getting the filename from full path name ?
in thread Getting the filename from full path name ?

It would be nice if File::Spec had a basename function, too. E.g. sub basename { (splitpath($_[0]))[-1] }. And probably also dirname.

Replies are listed 'Best First'.
Re: Re: Re: Re: Getting the filename from full path name ?
by demerphq (Chancellor) on Apr 15, 2004 at 13:20 UTC

    Why does it need one if it has splitpath() ?


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      • Fewer characters to type
      • I immediately see what is meant
      • There already is File::Basename::basename, and there's the unix utility called basename, hence it would be nice to have a function with the same name in the Perl standard library

        there's the unix utility called basename,

        And? Theres no such thing in Win32 nor a bunch of the other OS'es that Perl supports.

        Im sorry to be a bit snarky, but jusitfying a feature in perl by its existance in UNIX isnt actually a very helpful argument, Perl isnt UNIX and UNIX users arent even a majority in the community anymore.

        And IMO I fail to see how:

        my ($vol,$path,$filename)=splitpath($spec);

        is any less clear than using basename. And considering that a pathname often follows a basename id say its all the better because you get it all in one sub call. Anyway, if you feel better about having a basename sub then go right ahead, but I cant see people in p5p or Ken Williams agreeing. Hell, he even argued (and as maintainer won) that File::Spec shouldnt have a way to split arbitrary path strings properly, only one to split $ENV{PATH} itself. Which I personally thought was a pretty bad call. But whatever. :-)


        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi


      Let me second esserte's comment.

      Why do we need push() when we have splice(@a,@a,0,$x,$y)? Because primordial features, while powerful, are not always expressive in terms the reader will immediately recognize.

      --
      [ e d @ h a l l e y . c c ]

        Because "push" is an ancient an honorable function name of extremely creditable heritage, and the fact that the pesky newcomer 'splice' happens to do the same thing doesnt mean that the upstart will displace it. OTOH, "splitpath" is likely to easily understandable by anyone. Wheras 'basename' will only mean something to the minority that use UNIX. A loud vocal minority who think that no other OS users are worth considering or half the time even exist, but a minority nonetheless.

        Frankly if you are going to make a wrapper sub like this, have the decency not to be OS myopic about it and call it extract_filename() or something. Basename means nothing outside of UNIX.

        :-)


        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi