Mathew Snyder wrote:
> I'm trying to figure out how to use stat.  I have the following code:

You should really figure out how to use readdir

perldoc -f readdir


> #!/usr/bin/perl -w
> 
> use strict;
> 
> my @filenames;
> my $processDir = "/usr/bin";
> 
> opendir DH, $processDir or die "cannot open $processDir: $!";
> foreach my $file (sort(readdir DH)){
>         push @filenames, $file;
> }

Why not just:

my @filenames = sort readdir DH;


> closedir DH;
> 
> foreach my $filename (@filenames){
>         next if ($filename =~ /^.$|^..$/);
>         my $mod_time = (stat($filename))[9];

perldoc -f readdir
   readdir DIRHANDLE
           Returns the next directory entry for a directory opened by
           "opendir".  If used in list context, returns all the rest of the
           entries in the directory.  If there are no more entries, returns an
           undefined value in scalar context or a null list in list context.

           If you’re planning to filetest the return values out of a
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           "readdir", you’d better prepend the directory in question.
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           Otherwise, because we didn’t "chdir" there, it would have been
           testing the wrong file.

               opendir(DIR, $some_dir) || die "can’t opendir $some_dir: $!";
               @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
               closedir DIR;



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