Richard Noel Fell wrote: > > 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? > > 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; > }
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 = sort keys %Question_hash; my @ak = sort keys %Answer_hash; die "lengths of question hash and answer hash are not equal.\n" if @qk != @ak; chomp %Question_hash; for my $i ( 0 .. $#qk ) { print IN1 "Question$i:factor$Question_hash{$qk[$i]}=$Answer_hash{$ak[$i]}\n"; } close IN1; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]