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

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



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.

The people who write modules, especially modules that make it into the
core distirbution, tend to worry about things like that.  And Matthias
certainly has in his MacPerl modifications, which is why, for
instance, File::Copy Does The Right Thing with resource forks.  So
Vicki is right, get to know the FIle:: modules.  They're well tested,
and will help you avoid common mistakes like this.

} 
} You might also, depending upon what you are ultimately trying to
} accomplish, check into using cgi.pm to create and run your form.
} 
} Netscape and (I think) IE both allow file uploads in recent versions.  If
} you're trying, ultimately, to access the _file_, cgi.pm and file uploads
} make this very simple. CGI.pm handles accepting the file, opening it, and
} handing back a filehandle, all "magically".
} 
} Now in book form... CGI.pm makes forms based cgi-stuff easier.
} 
} - Vicki
} ---
}       |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
} ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
}      |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
}     '---''(_/--'  `-'\_)       http://www.cfcl.com/~vlb  www.ptf.com/macperl
} 

-- 
Paul Schinder
schinder@pobox.com