iwanthome has asked for the wisdom of the Perl Monks concerning the following question:
I would use File::Find to get the latest file in many directory. After I test the code,I found that code work normal if I send one directory to File::Find. But it would get wrong result if I send more than one directory to module. It seems like that File::Find would remember the variable.
execute result is like this:#!/usr/bin/perl use File::Find; $file = "/home/cmbnms/data/tftp/99.1.124.251"; my ($saved_time, $saved_name) = (-1, ''); sub biggest { if(-f $File::Find::name) { if ((stat($File::Find::name))[9] > $saved_time) { $saved_time = (stat($File::Find::name))[9]; $saved_name = $File::Find::name; } } return; } @dir = ($file); find(\&biggest, @dir); print "Biggest file $saved_name in is $saved_time long.\n"; $file = "/home/cmbnms/data/tftp/99.1.124.252"; @dir = ($file); find(\&biggest, @dir); print "Biggest file $saved_name in is $saved_time long.\n"; $file = "/home/cmbnms/data/tftp/10.1.102.237"; @dir = ($file); find(\&biggest, @dir); print "Biggest file $saved_name in is $saved_time long.\n"; $file = "/home/cmbnms/data/tftp/10.1.99.100"; @dir = ($file); find(\&biggest, @dir); print "Biggest file $saved_name in is $saved_time long.\n"; $file = "/home/cmbnms/data/tftp/10.1.99.200"; @dir = ($file); find(\&biggest, @dir); print "Biggest file $saved_name in is $saved_time long.\n";
Biggest file /home/cmbnms/data/tftp/99.1.124.251/2005-9-/15-20-24-99.1 +.124.251.conf in is 1126164026 long. Biggest file /home/cmbnms/data/tftp/99.1.124.252/2005-9-8/15-20-26-99. +1.124.252.conf in is 1126164027 long. Biggest file /home/cmbnms/data/tftp/10.1.102.237/2005-9-8/17-21-30-10. +1.102.237.conf in is 1126171290 long. Biggest file /home/cmbnms/data/tftp/10.1.102.237/2005-9-8/17-21-30-10. +1.102.237.conf in is 1126171290 long. Biggest file /home/cmbnms/data/tftp/10.1.102.237/2005-9-8/17-21-30-10. +1.102.237.conf in is 1126171290 long.
you can see that the last 3 result is same, but it is not truth.
thanks for your help!
Considered: marto: Retitle : "Possible File::Find bug" ?
Unconsidered: Chady: enough keep votes (edit:16 keep:23 del:0)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: bug of File::Find ?
by Corion (Patriarch) on Sep 09, 2005 at 07:06 UTC | |
by iwanthome (Beadle) on Sep 09, 2005 at 07:17 UTC | |
by ambrus (Abbot) on Sep 09, 2005 at 09:14 UTC | |
|
Re: bug of File::Find ?
by iwanthome (Beadle) on Sep 09, 2005 at 07:32 UTC |