Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: using File::Find to find recently-installed modules

by Marshall (Canon)
on Jun 24, 2016 at 13:51 UTC ( [id://1166501]=note: print w/replies, xml ) Need Help??


in reply to using File::Find to find recently-installed modules

stevieb is correct, creation time is not possible on Unix. It is possible on Windows, but the standard Perl built-in functions are not sufficient. I wrote this 6 years ago, might be helpful: Re^2: How to get the File creation date
  • Comment on Re: using File::Find to find recently-installed modules

Replies are listed 'Best First'.
Re^2: using File::Find to find recently-installed modules
by Aldebaran (Curate) on Jun 25, 2016 at 09:54 UTC

    I plead guilty to whatever XY drift there is in the unrolling specification here, but a proper sailor in high seas will not abandon his complete mystification without reporting it as well as he can, for others with better perspective perchance to hear. It would seem files in the local::lib are not possessed of a,c, or mtime, whilst my crummy modules have all 3. My current best script follows with abridged output.

    use strict; use warnings; use 5.014; use File::Find; my @directories_to_search = ( '.', 'C:\Users\Fred\Desktop' ); my @files; find( \&wanted, @directories_to_search ); my @time = localtime; say "local time is @time"; sub wanted { if ( $_ =~ m/.pm$/ ) { my $name = $File::Find::name; my $success = max_acm($name); say "max_acm is $success"; push( @files, $name ); } } sub max_acm { use strict; use 5.014; use warnings; my $path = shift; say "$path is $path"; my @array; push @array, 42; my $atime = ( stat $path )[8]; if ( defined $atime ) { say "atime is ok"; push @array, $atime; } my $ctime = ( stat $path )[10]; if ( defined $ctime ) { say "ctime is ok"; push @array, $ctime; } my $mtime = ( stat $path )[9]; if ( defined $mtime ) { say "mtime is ok"; push @array, $mtime; } my $max = ( sort { $b <=> $a } @array )[0]; return $max; }
    max_acm is 42 ./perl5/lib/perl5/Prompt/Timeout.pm is ./perl5/lib/perl5/Prompt/Timeou +t.pm max_acm is 42 ./perl5/lib/perl5/WWW/Mechanize/GZip.pm is ./perl5/lib/perl5/WWW/Mecha +nize/GZip.pm max_acm is 42 C:\Users\Fred\Desktop/alpaca/template_stuff/config1.pm is C:\Users\Fre +d\Desktop/alpaca/template_stuff/config1.pm atime is ok ctime is ok mtime is ok max_acm is 1465162519 C:\Users\Fred\Desktop/alpaca/template_stuff/html1.pm is C:\Users\Fred\ +Desktop/alpaca/template_stuff/html1.pm atime is ok ctime is ok mtime is ok max_acm is 1465162519

    The times I'm looking for *in this context* are bounded below by when they become files in this locale. As further indication of XY shift, I would stipulate that it is sufficient to take the max of them, just in order to make useful time comparisons that will work for gilligan's island. I could just as well write a min function, compare it to the max, and have an interesting statistic about age, but first I'm trying to get squared away with the material in the exercises. I'm still *finding* modules, so I have to wonder how perl is interpreting the underlying windows platform. That neither a,c nor m time for the unix installed modules exists knocks my socks off and, along with the sea forward and backslashes, makes me believe that my logic is faulty.

    Again, thanks for your comment.

      That neither a,c nor m time for the unix installed modules exists knocks my socks off and, along with the sea forward and backslashes, makes me believe that my logic is faulty.

      The issue is that you have a relative path, the '.' File::Find does a cd as it navigates downwards. By the time you do the file test, you are not where you think you are and the file test fails. Since you are actually "in the directory", you can use the simple name of the file, eg. just "Timeout.pm". File::Basename can get that from $File::Find::name. The branch which started with an absolute path name works fine because it doesn't matter what directory that you are in when you do the stat.

      update: It is not necessary to use "\" on Windows. The "/" will work just fine. That is also true from the command line. The "\" is a hold over from DOS days and causes obvious problems due to its special meaning in Perl.

      Also worthy of note are side effects of this changing working directory business. If you code something that could "blow up" in Find, you will be left in some random part of the directory tree.

      Update:
      Here is some code to demo what I've said. I started in the ".." directory and used basename($File::Find::name) to do a simple file test on the basename.

      #!/usr/bin/perl use warnings; use strict; use File::Find; use File::Basename; find (\&for_every_name,'..',); sub for_every_name { my $basename = basename($File::Find::name); return unless $basename =~ /\.pl$/; print "$File::Find::name\n"; my $access_age = -A $basename; print " $basename, acccess age in days: $access_age\n"; } __END__ Abridged output: ../SSPH_Results/cmpN1MMarrlresults.pl cmpN1MMarrlresults.pl, acccess age in days: 40.9642361111111 ../SSPH_Results/convert2oldCSV.pl convert2oldCSV.pl, acccess age in days: 17.5422685185185 .....deleted..... ../testing/FileFinder.pl FileFinder.pl, acccess age in days: 1.15740740740741e-005 Note: *** "FileFinder.pl" is the name of this file, hence the Note: *** very short last access time! ../testing/fileFindexample.pl fileFindexample.pl, acccess age in days: 0.110034722222222

        Thank you for this update: I was struggling with this syntax along with having a large reading burden to get into the whole pod scheme. I see now that it can be incremental, as pod is somehow syntactic perl. I had to wade through File::Find.pm just like they tell you to as well as WWW::Mechanize.pm, which I found astonishing under this view. I had never understood all this **clutter** in these modules that couldn't be perl, at least because it lacked semi-colons. So, yeah, light bulb, there.

        Maybe the castaways leave the coast when they get a pause account, define a local::lib, and declare their real intent to make a didactic effort at the material of gilligan's island.

        The castaways are logging their misadventures now:

        C:\Users\Fred\Documents>perldoc g7.pl DESCRIPTION This is a pretty good first attempt at figuring out where your mod +ules are. It is meant to follow the development of _Intermediate Perl_, + and I will adhere to the idioms. C:\Users\Fred\Documents>

        This is how I figured out what has been happening since the 16 days I've had a local::lib :

        #!/usr/bin/perl use warnings; use strict; use File::Find; use Cwd; =pod =head1 DESCRIPTION This is a pretty good first attempt at figuring out where your modules + are. It is meant to follow the development of _Intermediate Perl_, a +nd I will adhere to the idioms. =cut my $current = cwd; find( \&pm_beneath, $current, ); sub pm_beneath { use File::Basename; my $basename = basename($File::Find::name); return unless $basename =~ /\.pm$/; print "$File::Find::name\n"; my $access_age = -A $basename; print " $basename\n"; print "access age in days: $access_age\n\n"; } __END__

        Output for readmore tags. It's 300 lines of the Minnow being tossed:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1166501]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found