You might have been able to figure this out for yourself if your script didn't ignore useful clues. If a library routine returns an error by setting $!, check it! That means writing
Purists will tell you to also doopendir(DIR, 'c:/perl/test') or die "c:/perl/test: $!"; ... open(MYFILE, ">myfile.txt") or die "myfile.txt: $!"; open(THEFILE, "<$file") or die "$file: $!"; ...
in case the disk fills up and the script is unable to cleanly close the file.close(MYFILE) or die "c:/perl/test: $!";
That said, understanding that readdir() returns names, not paths, is key to understanding the problem. Here, consulting the perl documentation help. The blurb on readdir() in perlfunc spells it right out:
If you're planning to filetest the return values out of a readdir, you'd better prepend the directory in question. Otherwise, because we didn't chdir there, it would have been testing the wrong file.
In reply to Re: Directory Stuff
by dws
in thread Directory Stuff
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |