--- loncom/homework/default_homework.lcpm 2005/07/13 20:44:29 1.101 +++ loncom/homework/default_homework.lcpm 2005/11/16 22:18:22 1.104 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run() # -# $Id: default_homework.lcpm,v 1.101 2005/07/13 20:44:29 albertel Exp $ +# $Id: default_homework.lcpm,v 1.104 2005/11/16 22:18:22 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -193,7 +193,7 @@ sub caparesponse_check_list { my $type = $LONCAPA::CAPAresponse_args{'type'}; $result.="Got type :$type:\n"; if ($type ne '' && $#list > 0) { - (@responselist)=split /,/,$response; + (@responselist)=split(/,/,$response); } else { (@responselist)=($response); } @@ -217,18 +217,23 @@ sub caparesponse_check_list { $result.="trying answer :$list[$i]:\n"; my $thisanswer=$list[$i]; $result.="trying answer :$thisanswer:\n"; - if ($unit eq '') { - ($aresult,$msg)=&caparesponse_check($thisanswer,$responselist[$i]); + if (defined($list[$i])) { + if ($unit eq '') { + ($aresult,$msg)=&caparesponse_check($thisanswer, + $responselist[$i]); + } else { + ($aresult,$msg)=&caparesponse_check($thisanswer, + $responselist[$i]." $unit"); + } } else { - ($aresult,$msg)=&caparesponse_check($thisanswer, - $responselist[$i]." $unit"); + $aresult='ERROR'; } - my ($temp)=split /:/, $aresult; + my ($temp)=split(/:/, $aresult); $awards.="$temp,"; $result.=$aresult; push(@msgs,$msg); } - chop $awards; + chop($awards); return ("$awards:\n$result",@msgs); } @@ -451,14 +456,14 @@ sub random_negative_binomial { return @retArray; } -sub abs { abs(shift) } -sub sin { sin(shift) } -sub cos { cos(shift) } -sub exp { exp(shift) } -sub int { int(shift) } -sub log { log(shift) } -sub atan2 { atan2($_[0],$_[1]) } -sub sqrt { sqrt(shift) } +sub abs { CORE::abs(shift) } +sub sin { CORE::sin(shift) } +sub cos { CORE::cos(shift) } +sub exp { CORE::exp(shift) } +sub int { CORE::int(shift) } +sub log { CORE::log(shift) } +sub atan2 { CORE::atan2($_[0],$_[1]) } +sub sqrt { CORE::sqrt(shift) } sub tan { CORE::sin($_[0]) / CORE::cos($_[0]) } #sub atan { atan2($_[0], 1); } @@ -637,12 +642,12 @@ sub prettyprint { sub commaformat { my ($number,$target) = @_; if ($number =~ /\./) { - while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) { - $number = $1.','.$2.$3; + while ($number =~ /([^0-9]*)([0-9]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) { + $number = $1.$2.','.$3.$4; } } else { - while ($number =~ /([^,]+)([^,][^,][^,])([,0-9]*)$/) { - $number = $1.','.$2.$3; + while ($number =~ /^([^0-9]*)([0-9]+)([^,][^,][^,])([,0-9]*)$/) { + $number = $1.$2.','.$3.$4; } } return $number;