if else question



Hi All,

The first time I wrote this if else statement I wrote it correctly... now
I've confused myself... :~)

If the "if" statement returns false the program writes that line in the file
to $error_log for every $file in the directory.... I just what the line in
the file to be written one time... not one time for every file in the
directory... Perl is doing exactly what I have written... It's just not
what I want.. :~)

foreach line in the txtfile, match a file in the directory....print file.
....else print the line item in txtfile to the error_log....

How do I write the code so the line item only prints to the error_log one
time?


my $file_dir = "F:";
opendir(DIR, $file_dir) or die "Can't open the $file_dir: $!\n";

my @files = readdir(DIR) or die "Unable to read current dir:$!\n";
closedir(DIR);

my $orders_dir = "c:/orders";
opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";

@ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;

while (<>) {
chomp;

foreach my $file (@files) {
my $error_log = "c:/brian/test/no_file.txt";
open (NOFILE, ">> $error_log") or die "can't open $error_log:$!\n";

if ($_ eq $file) {
print $file;


#### This is printing $_ to the error_log one time for every file in the
directory
#### I just want it to print to the error_log one time if there is not a
match in the directory.

} else {
print NOFILE "\n";
}
}

closedir (ORDERS);


Thanks for your help!

Brian Volk
HP Products
317.298.9950 x1245
<mailto:bvolk@xxxxxxxxxxxxxx> bvolk@xxxxxxxxxxxxxx