in reply to file check loop

Does this work?:

#!/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 (@races) { for my $i (0..4) { if ( -s "/strek/$_/logs/rlog$i.sr.html" ) { } else { print "/strek/$_/logs/rlog$i.sr.html either does not exist or + is 0 bytes!\n"; } } }

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

    You don't want to initialize your array like so: my @races = undef; because like so, you already have an element in the array. Which is not what you want to do.
    You can simply do my @races = (); OR more better my @races; just like toolic posted above.

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re^2: file check loop
by AnomalousMonk (Archbishop) on Jul 30, 2013 at 15:48 UTC

    Well, does this work?

    >perl -wMstrict -le "opendir my $dh, '.' or die qq{opening .: $!}; while (defined(my $dname = readdir $dh)) { next unless { -d $dname }; print qq{dir '$dname'}; } " Odd number of elements in anonymous hash at -e line 1. dir '.' Odd number of elements in anonymous hash at -e line 1. dir '..' Odd number of elements in anonymous hash at -e line 1. dir '10001fr.equ' Odd number of elements in anonymous hash at -e line 1. dir '10002fr.equ' ... Odd number of elements in anonymous hash at -e line 1. dir 'Wrap_Simple.pm' Odd number of elements in anonymous hash at -e line 1. dir 'Wrap_Simple.pm.bak' Odd number of elements in anonymous hash at -e line 1. dir 'xxxx'