File::Find doesn't go down thru directory

C

cmic

Hello

Instead of mixing shell scripts and Perl, I prefer to do all the job
of the command find (recursion) and other piped commands with Perl.
However, the snippet below doesn't print any file under the current
directory.
The commented line (print "Result...) give the right information, if
uncommented, of \
course.

Any hint ? What do I
miss ,
--
michel marcon aka
cmic
Sysadmin.

#!/usr/local/bin/
perl
use
strict;
use
warnings;
use
File::Find;

find(\&wanted,
".");

sub wanted
{
my $file=
$File::Find::name;
# print "Result $file,
"\n";
if (-f $file )
{
print $file,
"\n";
}
}
 
R

Randal L. Schwartz

cmic> sub wanted
cmic> {
cmic> my $file=
cmic> $File::Find::name;
cmic> # print "Result $file,
cmic> "\n";
cmic> if (-f $file )
cmic> {
cmic> print $file,
cmic> "\n";
cmic> }
cmic> }

Hint: $File::Find::name will look like ./foo/bar, but you'll be cd'ed into
"./foo" already, so there's no ./foo/bar below ./foo.

If you're *in* "wanted", use $_.
If you're *after* "wanted", use $File::Find::name.

Don't confuse the two. They both have their purpose.

print "Just another Perl hacker,"; # the original
 
C

cmic

On 13 déc, 23:58, (e-mail address removed) (Randal L. Schwartz) wrote:
........
If you're *in* "wanted", use $_.
If you're *after* "wanted", use $File::Find::name.

Don't confuse the two. They both have their purpose.

OK I dig it now
Thx Randal. Sorry for the unformatted post..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,115
Latest member
JoshuaMoul
Top