How are you running this script? If you run it from the command line, you'll get these errors:
Global symbol "$dir" requires explicit package name at test.pl line 4.
Global symbol "$dir" requires explicit package name at test.pl line 5.
Global symbol "$dir" requires explicit package name at test.pl line 5.
Global symbol "$file" requires explicit package name at test.pl line 6
+.
Global symbol "$file" requires explicit package name at test.pl line 7
+.
Execution of test.pl aborted due to compilation errors.
If you're running the program by double-clicking on the file in Windows Explorer, you're probably not going to see the errors before the DOS box closes.
I think this code is what you want:
use strict;
use warnings;
my $dir = "C:\\parser_pgm\\test";
opendir(DIR, $dir) or die "Can't open $dir: $!";
while(my $file = readdir DIR) {
my $pathname = "$dir\\$file";
if (-f $pathname) {
# I added the -f test after running this and finding
# out that readdir returns "." and ".."
# (At least on the version of ActivePerl I am using)
print STDERR "running parser_pgm.exe on $pathname\n"; # for debugg
+ing
system("parser_pgm.exe \"$pathname\"");
# I added quotes in case there are spaces in the
# file name (or in directory name in case you change it.
if ($? != 0) {
print STDERR "parser_pgm returned error $?\n";
}
}
}
closedir(DIR);