http://qs321.pair.com?node_id=1166461

Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm working through the exercises in the alpaca book, to wit where the castaways have specified a local::lib and now seek to write a script that gives useful time data associated with these files. My needs are not exactly what the book calls for in any one exercise but range over several, so I used File::Find for the first time instead of relying on windows explorer to tell me where and what things are. (Uggh.)

In the last couple weeks, I've torn out and replaced an overgrown perl install with this machine, so I wanted to pay some attention to make this install a bit more robust, and consequently have strawberry perl. I had a false start on local::lib, which I hope won't matter in the scheme of things, which I only state so that no one could say "why didn't you tell us you had a screwy, abortive, previous attempt at creating a local::lib?" It may matter, may not. That's part of what I'm learning. Here's what I have now:

use strict; use warnings; use utf8; use 5.014; use File::Find; my @directories_to_search = ('.', 'C:\Users\Fred\Desktop'); my @files; find( \&find_module, @directories_to_search ); sub find_module { if ( $_ =~ m/.pm$/ ) { my $name = $File::Find::name; push( @files, $name ); } } for my $file (@files) { my $mtime = (stat $file)[9]; # mtime via slice my $when = localtime $mtime; print "$when: $file\n"; }

Output:

... Thu Apr 30 10:24:40 2015: ./alpaca/template_stuff/html1.pm Sun Jun 5 14:32:45 2016: ./alpaca/template_stuff/html2.pm Sun Jun 5 14:08:18 2016: ./alpaca/template_stuff/html3.pm Thu Apr 30 10:24:40 2015: ./alpaca/template_stuff/utils1.pm Wed Jun 9 08:59:19 2010: ./perl5/lib/perl5/HTML/ElementGlob.pm Wed Jun 9 08:24:01 2010: ./perl5/lib/perl5/HTML/ElementRaw.pm Wed Jun 9 13:56:58 2010: ./perl5/lib/perl5/HTML/ElementSuper.pm Wed Jun 9 16:17:31 2010: ./perl5/lib/perl5/HTML/ElementTable.pm Thu Feb 15 07:35:15 2007: ./perl5/lib/perl5/HTML/Extract.pm Thu May 21 09:22:21 2015: ./perl5/lib/perl5/HTML/TableExtract.pm Mon Nov 1 07:04:16 2010: ./perl5/lib/perl5/Prompt/Timeout.pm Wed Jun 24 04:07:26 2009: ./perl5/lib/perl5/WWW/Mechanize/GZip.pm

It appears that cpan modules are getting stored in a place that seems to have 'perl5' in it twice. Hope that's okay. Scripts are able to find these so far. Otherwise, I see that, unlike the professor, mtime is not what I'm looking for, as the time I'm interested in is when they got saved to this locale. Is there a perl way to make sure I own these? (The dot is 'Documents', so I would think so indeed.)

My quest for a "born-on" timestamp continued with reading up on stat, so I worked up versions of the same material using atime and ctime. I don't think I see the difference between the two, so I wonder which one works better as a "born-on" date in this context:

use strict; use warnings; use utf8; use 5.014; use File::Find; my @directories_to_search = ('.', 'C:\Users\Fred\Desktop'); my @files; find( \&find_module, @directories_to_search ); my @time =localtime; say "local time is @time"; sub find_module { if ( $_ =~ m/.pm$/ ) { my $name = $File::Find::name; push( @files, $name ); } } for my $file (@files) { my $atime = (stat $file)[8]; # atime via slice my $when = localtime $atime; print "$when: $file\n"; }

atime output:

local time is 13 44 19 23 5 116 4 174 1 Mon Jun 13 19:12:19 2016: ./alpaca/template_stuff/html1.pm Mon Jun 13 19:12:19 2016: ./alpaca/template_stuff/html2.pm Mon Jun 13 19:12:19 2016: ./alpaca/template_stuff/html3.pm Mon Jun 13 19:12:19 2016: ./alpaca/template_stuff/utils1.pm ... Wed Jun 22 22:09:13 2016: ./perl5/lib/perl5/HTML/ElementGlob.pm Wed Jun 22 22:09:13 2016: ./perl5/lib/perl5/HTML/ElementRaw.pm Wed Jun 22 22:09:13 2016: ./perl5/lib/perl5/HTML/ElementSuper.pm Wed Jun 22 22:09:13 2016: ./perl5/lib/perl5/HTML/ElementTable.pm Wed Jun 22 22:07:17 2016: ./perl5/lib/perl5/HTML/Extract.pm Wed Jun 22 22:08:24 2016: ./perl5/lib/perl5/HTML/TableExtract.pm Wed Jun 22 22:12:21 2016: ./perl5/lib/perl5/Prompt/Timeout.pm Wed Jun 22 22:06:40 2016: ./perl5/lib/perl5/WWW/Mechanize/GZip.pm

This has the useful information I need, and seems the same on inspection as the same script with the change of

 my $ctime = (stat $file)[10];

My intent is to make comparisons of time values part of the search criteria. I found many of these values astonishing and unexpected compared to the reading. Again my final question for moving forward is whether atime or ctime would serve as a better born-on date. Thank you for your comment.