develooper Front page | perl.perl5.porters | Postings from February 2003

[PATCH] Re: [perl #18872] File::Basename example misleading

Thread Next
Richard Soderberg
February 15, 2003 06:18
[PATCH] Re: [perl #18872] File::Basename example misleading
Message ID:
- resent to p5p, oops.

[ - Wed Dec  4 15:34:58 2002]:

> the documenation for File::Basename includes the example
>      $basename = basename("lib/File/",qr{\.pm});
> which leads the reader to think that the regular expression would be 
> processed reasonably.  I expected $basename to be set to "Basename" 
> but instead got ""
> If a suffix is going to be passed and used, perhaps the example should 
> be changed to:
>      $basename = basename("lib/File/",".pm");
> (which does yield "Basename".)

That's interesting; fileparse() accepts regexes for extensions, but 
basename() specifically \Q\E's the input, to *ensure* it's not a regex. 
  I've attached a patch against @18691 that updates the documentation, 
at least.

> I myself would prefer to instead recognize that a regexp was passed 
> in, and process in a way that that the given example with the 
> suffixlist set to qr{\.pm} would return $basename as "Basename" I'm 
> pretty sure the code today isn't doing what it should.

Is there any reason to change this behaviour?  Why was it \Q\E'd in the 
first place?

> I couldn't find a test case that in Basename.t that showed the given 
> example working one way or the other.

  - R.

# attached, corrupts inline diffs
--- lib/File/   2003-02-11 10:03:17.000000000 -0500
+++ lib/File/        2003-02-11 10:12:07.000000000 -0500
@@ -19,7 +19,7 @@

      ($name,$path,$suffix) = fileparse("lib/File/",qr{\.pm});
-    $basename = basename("lib/File/",qr{\.pm});
+    $basename = basename("lib/File/",".pm");
      $dirname = dirname("lib/File/");


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About