----- Original Message ----- From: Brian Volk <[EMAIL PROTECTED]> Date: Thursday, April 28, 2005 11:27 am Subject: if else question
> Hi All, Hello, > > The first time I wrote this if else statement I wrote it > correctly... now > I've confused myself... :~) That will happen often ! > > 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. I am not exactly sure what you want, but it sounds like you want exact oposite of what you already have ?? in which case, the following should do: if ($_ ne $file) { print $file;} HTH, Mark G. > > } else { > print NOFILE "\n"; > } > } > > closedir (ORDERS); > > > Thanks for your help! > > Brian Volk > HP Products > 317.298.9950 x1245 > <[EMAIL PROTECTED]> [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>