> > 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.
Mark, thank you for you help but actually the statement below is the one I'm having trouble getting correct. If the line item in the file does not match a filename in the directoy, print the line item to the error_log one time... right now it's printing the line item to the error_log, "NOFILE" one time for every file in the directory... So if I have a file w/ two line items (file names) that don't match a any of the files in the directoy, the error_log will have 50 entries for line item one and 50 entries for line item two.. > > > > > } else { > > print NOFILE "\n"; > > } > > } > > > > closedir (ORDERS); > > > > Thanks again! Brian > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>