--- loncom/interface/spreadsheet/Spreadsheet.pm 2003/06/18 15:32:37 1.13 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2003/06/18 17:35:14 1.14 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.13 2003/06/18 15:32:37 matthew Exp $ +# $Id: Spreadsheet.pm,v 1.14 2003/06/18 17:35:14 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -816,30 +816,32 @@ sub expandnamed { # 4. If there is a collision, return 'bad parameter name error' my $returnvalue = ''; my @matches = (); + my @values = (); $#matches = -1; study $expression; - my $parameter; - foreach $parameter (keys(%{$self->{'constants'}})) { - push @matches,$parameter if ($parameter =~ /$expression/); + while (my($parameter,$value) = each(%{$self->{'constants'}})) { + next if ($parameter !~ /$expression/); + push(@matches,$parameter); + push(@values,$value); } if (scalar(@matches) == 0) { $returnvalue = '""';#'"unmatched parameter: '.$parameter.'"'; } elsif (scalar(@matches) == 1) { # why do we not do this lookup here, instead of delaying it? - $returnvalue = '$c{\''.$matches[0].'\'}'; + $returnvalue = $values[0]; } elsif (scalar(@matches) > 0) { # more than one match. Look for a concise one $returnvalue = "'non-unique parameter name : $expression'"; - foreach (@matches) { - if (/^$expression$/) { + for (my $i=0; $i<=$#matches;$i++) { + if ($matches[$i] =~ /^$expression$/) { # why do we not do this lookup here? - $returnvalue = '$c{\''.$_.'\'}'; + $returnvalue = $values[$i]; } } } else { # There was a negative number of matches, which indicates # something is wrong with reality. Better warn the user. - $returnvalue = '"bizzare parameter: '.$parameter.'"'; + $returnvalue = '"bizzare parameter: '.$expression.'"'; } return $returnvalue; }