[31982] in Perl-Users-Digest
Perl-Users Digest, Issue: 3246 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 25 14:09:27 2010
Date: Sat, 25 Dec 2010 11:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 25 Dec 2010 Volume: 11 Number: 3246
Today's topics:
Oddity with File::Find and timestamps <dave@invalid.invalid>
Re: Oddity with File::Find and timestamps <skye.shaw@gmail.com>
Re: Oddity with File::Find and timestamps <dave@invalid.invalid>
Re: Oddity with File::Find and timestamps <tadmc@seesig.invalid>
Re: Oddity with File::Find and timestamps <skye.shaw@gmail.com>
Oddity with Find::File and -M <dave@invalid.invalid>
Re: Oddity with Find::File and -M <tadmc@seesig.invalid>
Re: Oddity with Find::File and -M <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Dec 2010 17:39:41 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Oddity with File::Find and timestamps
Message-Id: <fV45K0OBJxbE-pn2-es1VBVMtcLzl@localhost>
Playing with File::Find and I seem to have found an oddity.
In a "wanted" routine -M _ differs from -M $_ depending on whether one
processes files or not: Test directory has two sub directories in it.
[T:\tmp\Test]ls -lR
total 0
drwxrwx--- 0 Dec 24 14:42 dir1
drwxrwx--- 0 Dec 24 14:42 dir2
dir1:
total 0
-rw-rw---a 0 Dec 24 14:37 stuff1
dir2:
total 0
-rw-rw---a 0 Dec 24 14:42 stuff2
use strict;
use warnings;
use File::Find;
my $d = shift || '';
#print time(), "\n";
$^T=1293201891; # fix basetime to keep numbers the same between runs
finddepth(\¬wanted, '.');
exit;
sub notwanted
{
return if m/^\.$/; # Don't need '.'
return if $d && ! -d; # only directories
print $_, ' ';
print -M _, " ";
print -M $_, " ";
print "\n";
}
[T:\tmp\Test]../try.pl
stuff1 0.00533564814814815 0.00533564814814815
dir1 0.00533564814814815 0.00167824074074074
stuff2 0.00140046296296296 0.00140046296296296
dir2 0.00140046296296296 0.00149305555555556
[T:\tmp\Test]../try.pl d
dir1 0.00167824074074074 0.00167824074074074
dir2 0.00149305555555556 0.00149305555555556
find() and finddepth() do the same thing - which is not surprising as
it always does finddepth and inverts the results. It's not the OS.
Does the same thing on two different ones. OS/2 and Ubuntu.
Hmm.......... Knowing me I am missing something :-)
--
Regards
Dave Saville
------------------------------
Date: Fri, 24 Dec 2010 13:01:50 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: Oddity with File::Find and timestamps
Message-Id: <ffbecd46-8a45-41b4-ac66-fb732b0189f3@o14g2000prn.googlegroups.com>
On Dec 24, 9:39=A0am, "Dave Saville" <d...@invalid.invalid> wrote:
> Playing with File::Find and I seem to have found an oddity.
>
> In a "wanted" routine -M _ differs from -M $_ depending on whether one
> processes files or not:
>
> <snip directory listing and some code>
>
> finddepth(\¬wanted, '.');
> exit;
> sub notwanted
> {
> =A0 return if m/^\.$/; # Don't need '.'
> =A0 return if $d && ! -d; # only directories
> =A0 print $_, ' ';
> =A0 print -M _, " ";
> =A0 print -M $_, " ";
> =A0 print "\n"; =A0 =A0
>
> }
Try passing this function to findepth()
sub notwanted
{
return if m/^\.$/; # Don't need
'.'
return if $d && ! -d; # only
directories
print $_, ' ';
print -M _, " ";
print " (using a file's stat entry) " if -f _;
print -M $_, " (using ${_}'s stat entry)";
print "\n";
}
using _ will use the last stat() call's info.
See perldoc -f -X
-Skye
------------------------------
Date: Sat, 25 Dec 2010 09:33:34 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Oddity with File::Find and timestamps
Message-Id: <fV45K0OBJxbE-pn2-Q2JinvmYSeEe@localhost>
On Fri, 24 Dec 2010 21:01:50 UTC, "Skye Shaw!@#$"
<skye.shaw@gmail.com> wrote:
> On Dec 24, 9:39˙am, "Dave Saville" <d...@invalid.invalid> wrote:
> > Playing with File::Find and I seem to have found an oddity.
> >
> > In a "wanted" routine -M _ differs from -M $_ depending on whether one
> > processes files or not:
> >
> > <snip directory listing and some code>
> >
> > finddepth(\¬wanted, '.');
> > exit;
> > sub notwanted
> > {
> > ˙ return if m/^\.$/; # Don't need '.'
> > ˙ return if $d && ! -d; # only directories
> > ˙ print $_, ' ';
> > ˙ print -M _, " ";
> > ˙ print -M $_, " ";
> > ˙ print "\n"; ˙ ˙
> >
> > }
>
>
> Try passing this function to findepth()
>
> sub notwanted
> {
> return if m/^\.$/; # Don't need
> '.'
> return if $d && ! -d; # only
> directories
> print $_, ' ';
> print -M _, " ";
> print " (using a file's stat entry) " if -f _;
> print -M $_, " (using ${_}'s stat entry)";
> print "\n";
> }
>
>
[T:\tmp\test]../try1.pl
stuff1 0.00533564814814815 (using a file's stat entry)
0.00533564814814815 (usi
ng stuff1's stat entry)
dir1 0.00533564814814815 (using a file's stat entry)
0.00167824074074074 (using
dir1's stat entry)
stuff2 0.00140046296296296 (using a file's stat entry)
0.00140046296296296 (usi
ng stuff2's stat entry)
dir2 0.00140046296296296 (using a file's stat entry)
0.00149305555555556 (using
dir2's stat entry)
[T:\tmp\test]../try1.pl d
dir1 0.00167824074074074 0.00167824074074074 (using dir1's stat entry)
dir2 0.00149305555555556 0.00149305555555556 (using dir2's stat entry)
I don't see what that proved.
> using _ will use the last stat() call's info.
>
Yes, I know - but the point is the docs imply that $_ has been stat'ed
before wanted() gets control for each file/dir.
--
Regards
Dave Saville
------------------------------
Date: Sat, 25 Dec 2010 09:49:50 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Oddity with File::Find and timestamps
Message-Id: <slrnihc5br.7fe.tadmc@tadbox.sbcglobal.net>
Dave Saville <dave@invalid.invalid> wrote:
> On Fri, 24 Dec 2010 21:01:50 UTC, "Skye Shaw!@#$"
><skye.shaw@gmail.com> wrote:
>
>> On Dec 24, 9:39˙am, "Dave Saville" <d...@invalid.invalid> wrote:
>> > ˙ return if $d && ! -d; # only directories
When $d is false, there is no stat call.
>> return if $d && ! -d; # only
When $d is false, there is still no stat call.
> but the point is the docs imply that $_ has been stat'ed
> before wanted() gets control for each file/dir.
Huh?
What docs are you referring to?
$_ will have been stat()ed only when $d is true.
Since you want it to be stat()ed every time, you must do the file
test before you test the $d flag:
return if ! -d && $d;
I gave this solution to your problem yesterday in the duplicate
version of this thread.
Why did you start a duplicate version of this thread?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sat, 25 Dec 2010 10:47:33 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: Oddity with File::Find and timestamps
Message-Id: <a2334b8c-fad1-4f8e-81f6-a6ca0a76c18e@f20g2000prn.googlegroups.com>
> > > On Dec 24, 9:39 am, "Dave Saville" <d...@invalid.invalid> wrote:
> > > In a "wanted" routine -M _ differs from -M $_ depending on whether on=
e
> > > processes files or not:
> > On Fri, 24 Dec 2010 21:01:50 UTC, "Skye Shaw!@#$" wrote:
> > Try passing this function to findepth()
> > sub notwanted
> > {
> > =A0 =A0 return if m/^\.$/; # Don't need
> > '.'
> > =A0 =A0 return if $d && ! -d; # only
> > directories
> > =A0 =A0 print $_, ' ';
> > =A0 =A0 print -M _, " ";
> > =A0 =A0 print " (using a file's stat entry) " if -f _;
> > =A0 =A0 print -M $_, " (using ${_}'s stat entry)";
> > =A0 =A0 print "\n";
> > }
> On Dec 25, 1:33=A0am, "Dave Saville" <d...@invalid.invalid> wrote:
> I don't see what that proved.
It shows why you're not getting the output you expected.
> > using _ will use the last stat() call's info.
>
> Yes, I know - but the point is the docs imply that $_ has been stat'ed
> before wanted() gets control for each file/dir.
Your original question did not imply that certain functionality
described in the docs was not being obtained in your program.
See File::Find's follow and follow_fast options.
------------------------------
Date: Fri, 24 Dec 2010 15:24:06 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Oddity with Find::File and -M
Message-Id: <fV45K0OBJxbE-pn2-qfxnWkcjXLt6@localhost>
I am having problems with Find::File and -M _ in that I get different
values for directories depending on whether I process files or not.
use strict;
use warnings;
use File::Find;
my $d = shift || '';
#print time(), "\n";
$^T=1293201891; # fix basetime to keep numbers the same between runs
find(\¬wanted, '.');
exit;
sub notwanted
{
return if m/^\.$/; # Don't need '.'
return if $d && ! -d; # only directories
print $File::Find::dir,' ',$File::Find::name,' ',$_, ' ', -M _, " ";
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat $_;
printf "%20.17f\n", ($^T-$mtime)/86400; # convert mtime to format of
-M
}
File structure:
<somedir>
<dir1>
<dir2>
chdir'ed to <somedir>
[T:\tmp\test]../try.pl
. ./dir1 dir1 0.00149305555555556 0.00167824074074074
./dir1 ./dir1/stuff1 stuff1 0.00533564814814815 0.00533564814814815
. ./dir2 dir2 0.00533564814814815 0.00149305555555556
./dir2 ./dir2/stuff2 stuff2 0.00140046296296296 0.00140046296296296
[T:\tmp\test]../try.pl d
. ./dir1 dir1 0.00167824074074074 0.00167824074074074
. ./dir2 dir2 0.00149305555555556 0.00149305555555556
It looks as if the -M _ reported for a directory is not the same as
stat'ing it when files are processed. It would appear to have the
mtime of the last processed file. BTW it makes no difference if I use
find() or finddepth().
Or, as usual, am I missing something?
TIA
--
Regards
Dave Saville
------------------------------
Date: Fri, 24 Dec 2010 10:01:29 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Oddity with Find::File and -M
Message-Id: <slrnih9hlp.40u.tadmc@tadbox.sbcglobal.net>
Dave Saville <dave@invalid.invalid> wrote:
> I am having problems with Find::File and -M _ in that I get different
> values for directories depending on whether I process files or not.
>
> use strict;
> use warnings;
> use File::Find;
> my $d = shift || '';
> #print time(), "\n";
> $^T=1293201891; # fix basetime to keep numbers the same between runs
> find(\¬wanted, '.');
> exit;
> sub notwanted
> {
> return if m/^\.$/; # Don't need '.'
A test for equality should _look like_ a test for equality:
return if $_ eq '.'; # Don't need '.'
> return if $d && ! -d; # only directories
^^
^^
If $d is true, then -d is executed and _ is available for -M to use.
If $d is false, then -d is NOT executed and _ has a stale old
value from a previous iteration.
Do the file test first, so that it will always be executed:
return if ! -d && $d; # only directories
> print $File::Find::dir,' ',$File::Find::name,' ',$_, ' ', -M _, " ";
> my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
> $mtime, $ctime, $blksize, $blocks) = stat $_;
If you only need mtime, then slice out only the mtime:
my $mtime = (stat $_)[9];
> Or, as usual, am I missing something?
You guessed it! :-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Fri, 24 Dec 2010 10:07:37 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Oddity with Find::File and -M
Message-Id: <slrnih9i18.450.tadmc@tadbox.sbcglobal.net>
Tad McClellan <tadmc@seesig.invalid> wrote:
> my $mtime = (stat $_)[9];
Since we have now insured that there was a previous file test,
we can make that faster:
my $mtime = (stat _)[9];
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 3246
***************************************