in reply to print last file updated into directory


perldoc -f readdir and opendir to gain an understanding of the calls involved. this code and other exhaustive examples for directory listing are from perl meme website
#!/usr/bin/perl use strict; use warnings; my $dir = '/tmp'; opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { # We only want files next unless (-f "$dir/$file"); # Use a regular expression to find files ending in .txt next unless ($file =~ m/\.txt$/); print "$file\n"; } closedir(DIR); exit 0;

The temporal difficulty with perl is u need to know C well to know the awesome.else u just keep *using* it and writing inefficient code

Replies are listed 'Best First'.
Re^2: print last file updated into directory
by Anonymous Monk on Oct 31, 2014 at 01:47 UTC

    readdir is low-level

    use Path::Tiny qw/ path /; for my $kid ( path( $dir )->children( qr/\.txt$/ ) ){ print "$kid\n" if -f $kid; }

      Hello Anonymous Monk,
      By low level , is it that it is not an efficient way to traverse directory structures ?
      was just reading up about Path::Tiny on CPAN. It says it does not try to work in non-Windows and non-linux mode.
      also i see it has quite a few dependencies and wondering if it was pure perl or not, which might be a deciding factor for me ?
      I ran the following command to check the above
      perl -MPath::Tiny -MDynaLoader -E 'say for sort $@DynaLoader::dl_modul +es;'
      which gave me the output
      Cwd File::Glob

      The temporal difficulty with perl is u need to know C well to know the awesome.else u just keep *using* it and writing inefficient code