develooper Front page | perl.beginners | Postings from March 2002

Question about writing to file

Thread Next
From:
richard noel fell
Date:
March 28, 2002 11:00
Subject:
Question about writing to file
Message ID:
3CA36E2C.F7ACF5ED@rcn.com
Here is a subroutine that prints strings to a file. I want the routine
to write strings to the file in the format
Question1:factor(x^2+4*x+3)=(x+3)*(x+1).
However, what is written to file is
Question1:factor(x^2+4*x+3)
=(x+3)*(x+1), that is, 
a newline before the = sign. Is there some way of inhibiting this
behavior? 
Thanks,
Dick Fell



sub write_questions_and_correct_answers_to_file{
open In1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers"
or die "Cannot open factor_answers: $!";
my @qk; # temporary array to hold sorted questions keys
my @ak; # temporary array to hold sorted answer keys
my $qk; # temp variable to hold element of @qk
my $ak; # temp variable to hold element of @ak
@qk=sort(keys %Question_hash);
@ak=sort(keys %Answer_hash);
if ($#qk!=$#ak){
print "lengths of question hash and answer hash are not equal.\n";
exit();
}
else{
  for (my $i=1; $i<=$#qk+1;$i++){
print In1
"Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n";
}
}
close In1;
}

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About