my $inputfile = $ARGV[0]; my $outputfile = $ARGV[1]; open (OUTPUT_FILE, ">$outputfile"); my $Request_id; my $Variable_number; my $Variable; my $Choice; my @VARIABLE; my @CHOICE; my $Command; my $Return_results; my $Component_number_old = 1; my $Component_number = 1; my $SPROC; my $unique; my $elements_in_array; my $flat_file = $inputfile; open (FLAT_FILE, "<$flat_file"); while (){ chomp; $Component_number_old = $Component_number; if ($_ =~ /^$/) { exit; } elsif ($_ =~ /SPROC\sName\:\s([a-z|A-Z|0-9|_]{1,100})/){ $SPROC = $1; } elsif ($_ =~ /^\*(.{36})\;(\d{1,5})\;(\d{1,5})\;([a-z|A-Z|0-9|_]{1,50})\;(.{1,100})/){ push (@VARIABLE, $Variable); push (@CHOICE, $Choice); print "Hi_B\n"; $unique = $1; $Component_number = $2; $elements_in_array = $3; $Variable = $4; $Choice = $5; } if ($_ =~ /^\sEND/){ print "Hi_E\n"; push (@VARIABLE, $Variable); push (@CHOICE, $Choice); $Command = join(' ', 'EXEC', $SPROC, join(', ', @CHOICE[1 .. $elements_in_array])) . ';'; my $Request_id = $CHOICE[26]; Got_Command($Command, $Request_id, $outputfile); undef @CHOICE; my @CHOICE; } } close FLAT_FILE; sub Got_Command { my($Command,$Request_id, $outputfile) = @_; my $sthB_A = $dbh->do($Command) or die "Couldn't do query: ".$dbh->errstr; my $Return_results = "Select * from Result_storage_keep where Unique_identifier LIKE '".$Request_id."' AND Aggregated_area = Instance_name AND Disease_cat = Cause_catagory\;"; my $sth_C = $dbh->prepare($Return_results) or die "Couldn't prepare query: ".$dbh->errstr; $sth_C->execute() or die "Couldn't execute query: ".$sth_C->errstr; while (my @row = $sth_C->fetchrow_array) { print OUTPUT_FILE join("\t", @row); print OUTPUT_FILE "\n"; ## This is the bit that causes me problems ## I get the error messages # print() on closed filehandle OUTPUT_FILE at 20_October_2004_K.pl line 227, line 29. #print() on closed filehandle OUTPUT_FILE at 20_October_2004_K.pl line 228, line 29. } }