> > On 6/6/05, Brian Volk wrote: > > Hello All, > > > > I'm working w/ the File::Find module for the first time and > I'm having > > problems w/ my else statement.. If the query does not > match the first file > > in the directory, it will print the else statement. I > would like it the if > > statement to continue on to the next file in the directory > to see if that > > matches and if so, print the if statement > > > > Hi Brian, > I'm not sure what your problem is, I think you need to re-read > "perldoc File::Find". What you are describing ("would like... to > continue on to the next file") is exactly what File::Find does. Think > of it this way: for each search path you give "find()" as an argument, > &wanted will be executed once per every file in and under the given > path. > > Here's some simple code as an example: > ########## begin code > use strict; > use warnings; > use File::Find; > find(\&wanted, '.'); > sub wanted { > return if(m/^\./); > print "$_\n"; > } > ########## end code > This code will print the filename of every file (remember that > directories are considered files in Unix!) under the current > directory, except for "hidden" files. > > > > > undef $/; > > Why? > > > > > return if($_ =~ /^\./); > ... > > if ( m/$query/i ) { > > Why use 2 forms for matching $_? Try to be consistent, it really helps > readability... > > > stat $File::Find::name; > > > > Again, why? Especially as you are calling stat in empty context, > throwing away the return value. So why call it in the first place? > > HTH, > -- > Offer Kaye
Offer Kaye, Thank you for the response.. It really cleared things up.. It turns out all I need to do was move the last print statement outside of the sub. Thanks again for your help. Brian Volk #!/usr/bin/perl -w use strict; use File::Find; use CGI qw(:standard); my $query = param("query"); my $search_results = "http://www.company.com//"; my $no_search_results = "http://www.company.com/no_msds.htm"; find(\&wanted, '/var/www/html/msds'); sub wanted { if ( m/$query/i ) { print "Location: $search_results$_\n\n"; } } print "Location: $no_search_results\n\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>