spreadsheet by MG

while(<>){$y++;chomp;s/SQRT/sqrt/g;@a=split/\t/;$x=$#a if$#a>$x;map{$c=chr(65+$_);$v{"$c$y"}=$a[$_]}0..$#a}@o=keys%v;while($c=shift@o){$r=$v{$c};if($r=~m/^=/){@n=$r=~/[A-Z]\d+/g;$s=0;foreach(@n){if(exists($e{$_})){$r=~s/$_/$e{$_}/g}else{$s++}}if(!$s){eval('$e{'.$c.'}'.$r)}else{push @o,$c}}elsif($r=~m/^[\d.-]+$/){$e{$c}=$r+0}}map{$r=$_;$z='';;map{$c=chr(65+$_);if(exists$e{"$c$r"}){$o=sprintf"%.2f",$e{"$c$r"};$o=~s/\.*0{1,2}$//}else{$o=$v{"$c$r"}};$z.="$o\t"}0..$x;$z=~s/\t$/\n/;print$z}1..$y;

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page