in reply to Trouble opening and reading file within loop

/howard$: ls test Apr15 May15 testpm.dat EDI204_blah testing_all_Oct14.tar testpm2.pl /howard$: perl -d -e 1 ... main::(-e:1): 1 DB<1> $path='/howard/test/' DB<2> opendir(DH,$path) DB<3> @files=readdir(DH) DB<4> closedir(DH) DB<5> x @files 0 '.' 1 '..' 2 'Apr15' 3 'EDI204_blah' 4 'May15' 5 'testing_all_Oct14.tar' 6 'testpm.dat' 7 'testpm2.pl' DB<6> open $fh,'<',$files[6] or die $! No such file or directory at (eval 22)[/home/edi/perl/5.8.8/lib/5.8.8/ +perl5db.pl:628] line 2. DB<7> open $fh,'<',$path . $file or die $! DB<8> close $fh DB<9> @fglob = glob($path . "*") DB<10> x @fglob 0 '/howard/test/Apr15' 1 '/howard/test/EDI204_blah' 2 '/howard/test/May15' 3 '/howard/test/testing_all_Oct14.tar' 4 '/howard/test/testpm.dat' 5 '/howard/test/testpm2.pl' DB<11> open $fh,'<',$fglob[6] or die $! DB<12>

A couple things to note:

  1. readdir returned the . and .. links, glob did not
  2. Both returned both directories and files (Apr15 and May15 are directories).
    You will want to test to make sure $file is a file before you try to open it.
  3. readdir returned file name only, glob the whole path. That's why open $fh,'<',$files[6] failed.
    I needed to append the path before opening the file.
Dum Spiro Spero