Rajesh Dorairajan wrote:
> 
> From: John W. Krahn [mailto:[EMAIL PROTECTED]
> >
> > This should do what you want:
> >
> > use strict;
> > use warnings;
> > use File::Find;
> > use vars qw( $dir $name );
> > *dir  = *File::Find::dir;
> > *name = *File::Find::name;
> >
> > my $localdir = 'C:/docs';
> > my %files;
> >
> > find(
> >   sub {
> >     return unless -f;
> >     ( not exists $files{ $dir } or $files{ $dir }{ mtime } > -M _ )
> >       and ( @{ $files{ $dir } }{ qw/name mtime/ } = ( $name, -M _ ) )
> >     }, $localdir
> >   );
> >
> > for my $entry ( values %files ) {
> >   print $entry->{ name }, "\n";
> >   }
> >
> > __END__
> 
> Thanks for the script. I need to filter the result by a specific file
> extension, how do I that? I tried,
> 
>     ( not exists $files{ $dir } or $files{ $dir }{ mtime } > -M _ )
>       and ( @{ $files{ $dir } }{ qw/name mtime/ } = ( $name, -M _ ) )
>       and ( /^(full)\w*(\.db)$/ )

Just substitute:

    return unless -f;

With:

    return unless /^full\w*\.db$/;


> It does not seem to work. Actually I would be grateful if you could also
> help me understand how the script works. I cannot figure out the what role _
> plays. I know -M is "Script start time minus file modification time, in
> days".

_ is a special file handle that works with the file test operators.

perldoc -f -X
[snip]
       If any of the file tests (or either the `stat' or
       `lstat' operators) are given the special
       filehandle consisting of a solitary underline,
       then the stat structure of the previous file test
       (or stat operator) is used, saving a system call.
       (This doesn't work with `-t', and you need to
       remember that lstat() and `-l' will leave values
       in the stat structure for the symbolic link, not
       the real file.)  Example:

           print "Can do.\n" if -r $a || -w _ || -x _;

           stat($filename);
           print "Readable\n" if -r _;
           print "Writable\n" if -w _;
           print "Executable\n" if -x _;
           print "Setuid\n" if -u _;
           print "Setgid\n" if -g _;
           print "Sticky\n" if -k _;
           print "Text\n" if -T _;
           print "Binary\n" if -B _;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to