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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>