Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Noob File::Find issue

by bgreg (Initiate)
on Apr 30, 2012 at 22:33 UTC ( #968172=perlquestion: print w/replies, xml ) Need Help??
bgreg has asked for the wisdom of the Perl Monks concerning the following question:

I could use some help, I'm missing a fundamental somewhere. The following lines produce:
Undefined subroutine &main::find called at use FILE::Find; use warnings; find ( \&wanted, $directory); sub wanted{ print $File::File::dir; }
This is on active state Perl for Windows XP. Thanks in advance. - bGreg

Replies are listed 'Best First'.
Re: Noob File::Find issue
by GrandFather (Sage) on Apr 30, 2012 at 23:00 UTC

    The main issue is that Perl is case sensitive and that the module is actually File::Find. On a case insensitive file system you get weird results such as this because the module file gets found despite the error in the file name case, but the package isn't found.

    Note that you need $File::Find::dir to access the dir variable too. This should have been caught with warnings - you'd have gotten:

    Name "File::File::dir" used only once: possible typo at line + 12.

    when you ran the script.

    True laziness is hard work
Re: Noob File::Find issue
by thezip (Vicar) on Apr 30, 2012 at 23:01 UTC

    Heya bgreg,

    You've managed to capitalize the File in FILE::Find.

    Try this instead:

    use strict; use warnings; use File::Find; ... etc.

    Oh and BTW, make sure you use strict too!

    Welcome to Perl and Perlmonks!

    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens, 1949-2011
Re: Noob File::Find issue
by thomas895 (Chaplain) on May 01, 2012 at 01:53 UTC

    Also, not all modules export their subroutines. I have no idea if File::Find does(and I'm too lazy to check), so you might have to do one of the following:

    #These statements are equivalent use File::Find qw( find ); use File::Find 'find';
    I personally find it good practice(by my own conventions) to do that, just to make it clearer to myself where a function comes from. Your choice, ultimately.

    ~Thomas~ I believe that the source code to life is written in Perl :-)

      If I'm interested in knowing where stuff comes from I do exactly the opposite:

      use File::Find qw(); ... File::Find::find(...);

      By the time I'm a few dozen lines away from the top of the file I've probably completely forgotten where find() came from. A sometimes other benefit of being explicit is that if there is a 'find' in several different modules that are in use then it is clear which one is wanted.

      True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://968172]
Approved by GrandFather
[ambrus]: Corion: Is their budget estimate four times the initial estimate yet? Was the construction late by six months already three months after they started?
[marto]: I'll believe it when I see it. That's been due for many years now :P
[marto]: oddly the last time I was there I saw a zeppelin in flight for the first time
[Corion]: ambrus: I don't know how far the budget estimate has been overrun yet
[Corion]: marto: Heh ;) No, you were likely at Tegel or Schönefeld, the new one ("BER") will be somewhat outside of Berlin ;)
[marto]: Corion Schoenfeld, but my friend has been telling me about this new airport for about 7-8 years now :P
[marto]: I doubt it even exists as a building site :P

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-02-23 11:58 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (346 votes). Check out past polls.