You're not getting the errors you should because
meansopen INFILE,'<$name' || warn ("Cannot open input file $name\n");
which is the same as the following (since '<$name' is always true):open INFILE, ( '<$name' || warn ("Cannot open input file $name\n") );
open INFILE, '<$name'
You want to use parens or lower-precedence "or":
oropen(INFILE, '<$name') || warn ("Cannot open input file $name\n");
open INFILE, '<$name' or warn ("Cannot open input file $name\n");
Then there's the problem that '<$name' produces the five character < $ n a m e. You need to use double-quote to interpolate.
Or better yet, use the safer, more reliable 3-arg open:open(INFILE, "<$name") or warn ("Cannot open input file $name\n");
open(INFILE, '<', $name) or warn("Cannot open input file $name: $!\n");
Finally, $_ only contains the name of the file, not the path to the file. You need to use $File::Find::name.
open(INFILE, '<', $File::Find::name) or warn("Cannot open input file $File::Find::name: $!\n");
There's also a problem with
"$directory\$name"
The backslash before the $ tells Perl to treat the $ as a non-special character. You want
"$directory\\$name"
The following would also be fine:
"$directory/$name"
Yes, even on Windows. Windows accepts both slashes.
In reply to Re: How to open files found via File::Find
by ikegami
in thread How to open files found via File::Find
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |