[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Thu, 21 Nov 2002 18:56:36 -0000
matthew Thu Nov 21 13:56:36 2002 EDT
Modified files:
/loncom/interface lonspreadsheet.pm
Log:
Fix two bugs -
&exportsheet caused bad cache data to be stored away and cache data to be
improperly loaded. This was caused by the programmer (who shall remain me)
not properly rewriting some of the old code. I'd like to have fixed this
by making the caching more straightforward but that will have to wait.
&loadstudent - using while(my($key,$value) = each(%hash)) { ... } is
not a good idea if you modify %hash (specifically by adding more keys
to it) inside the loop. Best to use foreach my $key (keys(%hash)) and
take the (minor) performance hit in this case.
That latter is a horribly insidious bug that will haunt me until the end
of my days.
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.144 loncom/interface/lonspreadsheet.pm:1.145
--- loncom/interface/lonspreadsheet.pm:1.144 Wed Nov 20 11:46:31 2002
+++ loncom/interface/lonspreadsheet.pm Thu Nov 21 13:56:36 2002
@@ -1,5 +1,5 @@
#
-# $Id: lonspreadsheet.pm,v 1.144 2002/11/20 16:46:31 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.145 2002/11/21 18:56:36 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2365,7 +2365,8 @@
undef @tmp;
#
my @assessdata=();
- while (my ($cell,$value) = each (%formulas)) {
+ foreach my $cell (keys(%formulas)) {
+ my $value = $formulas{$cell};
if(defined($c) && ($c->aborted())) {
last;
}
@@ -2377,18 +2378,15 @@
$sheet->{'udom'},
'assesscalc',$usy,$ufn,$r);
my $index=0;
- foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
- 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
+ foreach my $col ('A','B','C','D','E','F','G','H','I','J','K','L','M',
+ 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
if (defined($assessdata[$index])) {
- my $col=$_;
if ($assessdata[$index]=~/\D/) {
$constants{$col.$row}="'".$assessdata[$index]."'";
} else {
$constants{$col.$row}=$assessdata[$index];
}
- unless ($col eq 'A') {
- $formulas{$col.$row}='import';
- }
+ $formulas{$col.$row}='import' if ($col ne 'A');
}
$index++;
}
@@ -2689,6 +2687,7 @@
#
sub exportsheet {
my ($sheet,$uname,$udom,$stype,$usymb,$fn,$r)=@_;
+ my $flag = 0;
$uname = $uname || $sheet->{'uname'};
$udom = $udom || $sheet->{'udom'};
$stype = $stype || $sheet->{'sheettype'};
@@ -2757,14 +2756,24 @@
[$key],
$sheet->{'cdom'},$sheet->{'cnum'});
if ($tmp[0]!~/^error/) {
- %currentlystored = @tmp;
+ # We only got one key, so we will access it directly.
+ foreach (split('___&___',$tmp[1])) {
+ my ($key,$value) = split('___=___',$_);
+ $key = '' if (! defined($key));
+ $currentlystored{$key} = $value;
+ }
}
} else {
my @tmp = &Apache::lonnet::get('nohist_calculatedsheets_'.
$sheet->{'cid'},[$key],
$sheet->{'udom'},$sheet->{'uname'});
if ($tmp[0]!~/^error/) {
- %currentlystored = @tmp;
+ # We only got one key, so we will access it directly.
+ foreach (split('___&___',$tmp[1])) {
+ my ($key,$value) = split('___=___',$_);
+ $key = '' if (! defined($key));
+ $currentlystored{$key} = $value;
+ }
}
}
#