in reply to file check loop

You've a typo in the line:

if ( -s '/strek/$race/logs/rlog$i.sr.html' ) {

Since you use single quotes $race and $i are not substituted by their value. Just try:

if ( -s "/strek/$race/logs/rlog$i.sr.html" ) {

Replies are listed 'Best First'.
Re^2: file check loop
by hippo (Archbishop) on Jul 30, 2013 at 17:44 UTC

    My anonymous brother is quite right. You can avoid this sort of problem (where by you test one thing but actually report another) by using a variable name for both. eg.

    my $file = "/strek/$race/logs/rlog$i.sr.html"; if ( -s $file ) { next; } else { print "$file either does not exist or is 0 bytes!\n"; }

    Other things you could do include making more use of the $ldir variable and rolling the second loop into the first.

    #!/usr/bin/perl use strict; use warnings; my $ldir = '/strek'; my @races = undef; opendir my $dh, $ldir or die "$0: opendir: $!"; while (defined(my $name = readdir $dh)) { next unless -d "$ldir/$name"; push (@races, $name); for my $i (0..4) { my $file = "$ldir/$name/logs/rlog$i.sr.html"; if ( -s $file ) { next; } else { print "$file either does not exist or is 0 bytes!\n"; } } } # Now do something useful with @races here