SPUG: Opening files

Scott Blachowicz Scott.Blachowicz at seaslug.org
Fri Jan 28 19:13:18 CST 2000


On Fri, Jan 28, 2000 at 04:48:08PM -0800, Daniel V. Ebert wrote:
> 
> I'm trying to write some code to pull out the title from some HTML files.   
> Below is the code I am using to get the filenames ... when $filename is a  
> file in a subdirectory it dies (because it can't open the file).  I am  
> guessing that this has something to do with the "/" character in the string  
> $filename.
> 
> Any ideas?

Well...the docs for File::Find mention that it does a chdir to each
directory it enters.  That $File::Find::name var is the full path from
the top and if these are relative paths, that probably isn't what you
want.  I think you just want to open "$_" which holds the current
filename (and $File::Find::dir is the containing directory).

> 
> #!/usr/bin/perl	
> @ARGV = qw(.) unless @ARGV;
> use File::Find;	
> 
> find sub {
> 
> 	if ($File::Find::name =~ /^\.\/admin/ ||
> 	    $File::Find::name =~ /^\.\/deleted/) {} #skip files in subdirs
> 
> 	elsif ($File::Find::name =~ /\.html/) { #only process .html files
> 		$filename = $File::Find::name;
> 		$filename =~ s/\.\///; #remove the ./ from start of $filename
> 
> 
> 	open (HTMLFILE, $filename) or die;
> 	@htmlfile = <HTMLFILE>;
> 	close (HTMLFILE);
> 	}
> #DO OTHER STUFF
> }

Scott.Blachowicz at seaslug.org

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list