Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Listing files

by BeernuT (Pilgrim)
on Feb 12, 2002 at 21:05 UTC ( #144986=note: print w/replies, xml ) Need Help??


in reply to Listing files

k, borrowing metadoktor's get_month_year sub, here is what i come up with.
use strict; use warnings; use File::Find; my $dir = 'c:'; my $search_month = 1; my $search_year = 2002; find(\&wanted, $dir); sub wanted { my $content = $_; if(-f $content) { my($month, $year) = get_month_year($content); if(($month eq $search_month) && ($year eq $search_year)) { print "$content was last accessed in $month of $year\n"; } } } sub get_month_year { my $file = shift; my @params = stat $file; my @dparams = localtime($params[9]); my $month = $dparams[4] + 1; my $year = $dparams[5] + 1900; return($month, $year); }


this can probably be made smaller but this will be good to help you understand. Play around with the stat command, its easy and you'll thank yourself later.


-bn

Replies are listed 'Best First'.
Re: Re: Listing files
by oaklander (Acolyte) on Feb 13, 2002 at 12:07 UTC
    Can someone explain what this 'shift' word is doing in this subroutine???
    sub get_month_year { my $file = shift; #PLEASE EXPLAIN WHAT SHIFT IS DOING? my @params = stat $file; my @dparams = localtime($params[9]); my $month = $dparams[4] + 1; my $year = $dparams[5] + 1900; return($month, $year); }
      The shift in the code is there to return the directory that is passed in the get_month_year. In the get_month_year sub the parent directory is needed - the shift operator does this by shifting the first value of the array off and returning it (the parent directory 'c:' in this case).

      You can find more info on the shift node.

Re: Re: Listing files
by oaklander (Acolyte) on Feb 13, 2002 at 10:48 UTC
    Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-12-01 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?