Mailing List Archive

Possible File::Find bug
First off, I apologize for sending this to the perl5-porters list. I have
temporarily lost Usenet access; could anyone point me towards a good
mail->usenet gateway so I could send this to comp.lang.perl.misc before
reporting it here?

I've been using Perl 5 for quite a while, but I just recently tried to
update some of my sysadmin scripts to use the Perl 5 File::Find. After a
little head-scratching, I realized that $dir and $name were not getting set
correctly in &wanted. Does the following code work for anyone else:

-- begin excerpt of test program --

#!/usr/local/bin/perl

require 5;

use File::Find;

find(\&wanted, '/home/jared/tmp/find-test');

sub wanted {
print "Dir: $dir\tFile: $_\tName: $name\n";

}

-- end excerpt of test program --

I'm using it on the following tree:

-- begin excerpt of tree --

/home/jared/tmp/find-test:
total 6
drwxrwxr-x 5 jared staff 512 Aug 25 12:51 ./
drwxrwxr-x 8 jared staff 512 Aug 25 12:46 ../
drwxrwxr-x 2 jared staff 512 Aug 25 12:47 A/
drwxrwxr-x 3 jared staff 512 Aug 25 12:46 B/
drwxrwxr-x 3 jared staff 512 Aug 25 12:47 C/
-rwxrwxr-x 1 jared staff 162 Aug 25 12:51 find*

/home/jared/tmp/find-test/A:
total 3
drwxrwxr-x 2 jared staff 512 Aug 25 12:47 ./
drwxrwxr-x 5 jared staff 512 Aug 25 12:51 ../
-rw-rw-r-- 1 jared staff 4 Aug 25 12:47 a1

/home/jared/tmp/find-test/./A:
total 3
drwxrwxr-x 2 jared staff 512 Aug 25 12:47 ./
drwxrwxr-x 5 jared staff 512 Aug 25 12:51 ../
-rw-rw-r-- 1 jared staff 4 Aug 25 12:47 a1

/home/jared/tmp/find-test/B:
total 3
drwxrwxr-x 3 jared staff 512 Aug 25 12:46 ./
drwxrwxr-x 5 jared staff 512 Aug 25 12:51 ../
drwxrwxr-x 2 jared staff 512 Aug 25 12:46 BB/

/home/jared/tmp/find-test/B/BB:
total 4
drwxrwxr-x 2 jared staff 512 Aug 25 12:46 ./
drwxrwxr-x 3 jared staff 512 Aug 25 12:46 ../
-rw-rw-r-- 1 jared staff 4 Aug 25 12:46 b1
-rw-rw-r-- 1 jared staff 7 Aug 25 12:46 b2

/home/jared/tmp/find-test/C:
total 4
drwxrwxr-x 3 jared staff 512 Aug 25 12:47 ./
drwxrwxr-x 5 jared staff 512 Aug 25 12:51 ../
drwxrwxr-x 2 jared staff 512 Aug 25 12:47 CC/
-rw-rw-r-- 1 jared staff 4 Aug 25 12:47 c1

/home/jared/tmp/find-test/C/CC:
total 3
drwxrwxr-x 2 jared staff 512 Aug 25 12:47 ./
drwxrwxr-x 3 jared staff 512 Aug 25 12:47 ../
-rw-rw-r-- 1 jared staff 7 Aug 25 12:47 cc1

-- end excerpt of tree --

It gives me the following output:

-- begin excerpt of results --

Dir: /home/jared/tmp/find-test File: . Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: A Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: a1 Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: B Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: BB Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: b1 Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: b2 Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: C Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: c1 Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: CC Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: cc1 Name: /home/jared/tmp/find-test
Dir: /home/jared/tmp/find-test File: find Name: /home/jared/tmp/find-test

-- end excerpt of results --

These particular results are for Perl 5.001m on both Solaris and BSDI.

If I use finddepth instead, I get these results:

-- begin excerpt of finddepth results --

Dir: File: a1 Name:
Dir: File: A Name:
Dir: File: b1 Name:
Dir: File: b2 Name:
Dir: File: BB Name:
Dir: File: B Name:
Dir: File: c1 Name:
Dir: File: cc1 Name:
Dir: File: CC Name:
Dir: File: C Name:
Dir: File: find Name:
Dir: /home/jared/tmp/find-test File: . Name: /home/jared/tmp/find-test

-- end excerpt of finddepth results --

--
Jared_Rhine@hmc.edu / Organic Online / <URL:http://www.hmc.edu/~jared/home>

"Prohibition goes beyond the bounds of reason in that it attempts to control a
man's appetite by legislation and makes crimes out of things that are not
crimes. A prohibition law strikes a blow at the very principles upon which
our government was founded." -- Abraham Lincoln
Re: Possible File::Find bug [ In reply to ]
>From: Jared Rhine <jared@organic.com>
>correctly in &wanted. Does the following code work for anyone else:
>
>-- begin excerpt of test program --
>
>#!/usr/local/bin/perl
>
>require 5;
>
>use File::Find;
>
>find(\&wanted, '/home/jared/tmp/find-test');
>
>sub wanted {
> print "Dir: $dir\tFile: $_\tName: $name\n";
>
>}

It's a known bug (NETaa13527), workaround is to use $File::Find::name
and $File::Find::dir.

I'm inclined to call it a documentation bug, but so far the porters
haven't found an agreement on (nor a fix for) the matter.


andreas