in reply to Getting oversize file into an array help!

use strict ; use warnings ; my @directories = qw( /files1 /files2) ; my $min_size = 1024 ; my $max_size = 1048576 ; #1MB my @small_files ; my @big_files ; for my $dir (@directories) { for my $file (read_dir( $dir, prefix => 1 )) { next if (! -f $file || -s $file < $min_size) ; if (-s $file <= $max_size} { push(@small_files, $file) } else { push(@big_files, $file) ; } } }

Replies are listed 'Best First'.
Re^2: Getting oversize file into an array help!
by Anonymous Monk on Oct 25, 2011 at 18:35 UTC
    read_dir( $dir, prefix => 1 )

    On my machine, setting prefix to true doesn't prepend the path to the filename. I had to do it manually.

    Enter a line like:

    for my $file (read_dir( $dir, prefix => 1 )) { substr $file, 0, 0, "$dir/"; next if (! -f $file || -s $file < $min_size) ; ...