John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I'm a little rusty, so I suppose it could be a stupid mistake I'm just not seeing:
use v5.8.8; use strict; use warnings; use File::Find; sub wanted { # $File::Find::dir is the current directory name, # $_ is the current filename within that directory # $File::Find::name is the complete pathname to the file. print "[$File::Find::dir], [$_], [$File::Find::name]\n"; } sub main() { my $arg= shift @ARGV; print $arg, "\n"; find ({wanted => &wanted }, $arg); } main;
No matter what I give as the argument, it gives me three errors about concatenating undefined values on the print line, and: Can't use string ("1") as a subroutine ref while "strict refs" in use at I:/Program Files/Languages/Perl5/lib/File/Find.pm line 822. and this only happens once, so the find is not iterating over all the files in the directory. Please help an old monk? --John Active Perl build 816 running on WinXP Pro.

Replies are listed 'Best First'.
Re: File:Find doing weird stuff
by idsfa (Vicar) on Mar 23, 2006 at 05:55 UTC

    wanted wants a reference to a sub ...

    find ({wanted => \&wanted }, $arg);

    See the docs and perlref for more info. Your error message is telling you that the value of &wanted (namely, true aka 1) is not a reference ...


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon