On Tue, 4 Feb 2003, Wiggins d'Anconia wrote:

> Arild Jensen wrote:
> > I am trying to get the mtime of a bunch of files and directores. However, 
> > it fails after the first two files/dirs. I don't see why it should. I am 
> > an experienced sysadmin and a beginner Perl coder (obviously).
> > 
> > Help.
> > 
> > 
> > 
> > Source code:
> > 
> > #!/usr/bin/perl -w
> > 
> > use strict;
> > use File::Find;
> > use File::stat;
> > 
> > find(\&syswanted, '/mnt/Backup');
> > 
> > #########################################################################
> > sub syswanted {
> >     my $current_mtime;
> > 
> >     print "File: $_\n";
> >     $current_mtime = lstat($_)->mtime;
> >     print "MTime: $current_mtime \n";
> > 
> > 
> > }
> > #########################################################################
> > # The end.
> 
> I am curious if this is a bug in Perl's implementation of File::stat, 
> from the 5.8.0 perldoc File::stat:
> 
> "As of Perl 5.8.0 after using this module you cannot use the implicit $_
> or the special filehandle "_" with stat() or lstat(), trying to do so
> leads into strange errors."
> 
> I realize you said you are using 5.6.1 but this seems rather strange, 
> you might consider trying the regular built-in stat/lstat. (Do you 
> really want lstat over stat, there were no symlinks in your list?)
> 
> sub syswanted {
>    my $file = $_;
>    print "File: $file\n";
>    $current_mtime = (stat($file))[9];
>    print "MTime: $current_mtime\n";
> }
> 
> perldoc -f stat
> perldoc -f lstat
> perldoc File::stat (see if there is a 'Bugs' entry in 5.6.1)
> 
> Sorry I don't have a 5.6.1 install around I can test with....

Your suggested code produces almost the same results:

# ./test2.pl
File: .
MTime: 1044452317 
File: carbon.sysbu.2002-11-10.tar.bz
MTime: 1037055058 
File: carbon.ibu.2003-01-30.tar.bz2
Use of uninitialized value in concatenation (.) or string at ./test4.pl 
line 15.MTime:  
File: carbon.ibu.2003-01-29.tar.bz2
Use of uninitialized value in concatenation (.) or string at ./test4.pl 
line 15.MTime:  
File: carbon.ibu.2003-02-03.tar.bz2
Use of uninitialized value in concatenation (.) or string at ./test4.pl 
line 15.MTime:  
File: lithium.sysbu.2002-11-17.tar.bz
MTime: 1037582013 
File: lithium.sysbu.2002-11-17b.tar.bz
MTime: 1037591100 
File: carbon.ibu.2003-02-04.tar.bz2
Use of uninitialized value in concatenation (.) or string at ./test4.pl 
line 15.MTime:  
File: lost+found
MTime: 1036964040 

However, after installing Perl 5.8.0 from source, both scripts work fine. 
Looks like a 5.6.1 bug fixed in 5.8.0.

Thank you very much for your help.

-A



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to