[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] How do I get filename from a URL ?



Paul J. Schinder wrote:
> 
> On Fri, Jan 22, 1999 at 12:03:19PM -0800, Vicki Brown wrote:
> } At 09:33 -0800 1/22/99, Lars G. Skjellerup wrote:
> } > I have a FORM (on a HTML-page on a server). I get all the right
> } > info to my CGI (if I output it on a page I can read all that is
> } > expected) - but now I would very much like to extract a filename
> } > from a path.
> } 
> } 
> } At 09:48 -0800 1/22/99, Paul J. Schinder wrote:
> } > use File::Basename;
> } >
> } > $Fname = basename($Filename);
> } 
> } 
> } At 11:17 -0800 1/22/99, Christopher F. Blanford wrote:
> } > $file =~ m!(:|/)(.*)$!;
> } > $Fname = $2;
> } 
> } I would second Paul. File::Basename is more portable as well as tested/
> } standard/ etc... It even handles, can you believe it, VMS filenames ;-)
> } Get to know the File:: modules; they are your friends.
> 
> Not to mention that that regular expression won't work in all cases.
> Mac filenames can have / in them, and Unix filenames can have :.  This
> regex wont work right in those cases.
> 

That regex will not work at all.  It matches from the *first* "directory
separator" to the end of the string, but the filename starts at the *last*
directory separator.

The code also refers to $2 without making sure the match actually
succeeded, so $2 could still have its value from an earlier match.

Ronald

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch