Mercurial > hg > batmud > misc
changeset 256:0adaafd9d6e8 misc
Stabler sorting for text output.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Mar 2015 02:40:16 +0200 |
parents | af08f54f0bc6 |
children | 8ba1da42b219 |
files | materials/parsealloys.pl |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/materials/parsealloys.pl Sun Mar 08 02:40:05 2015 +0200 +++ b/materials/parsealloys.pl Sun Mar 08 02:40:16 2015 +0200 @@ -31,7 +31,7 @@ sub addCombo($$$) { if (!$fumble) { - push(@{$data{$_[0]}{$_[1]}}, $_[2]); + push(@{$data{$_[1]}{$_[2]}}, $_[0]); } else { print STDERR "Ignoring fumbled combo $_[0] + $_[1] = $_[2]\n"; } @@ -41,9 +41,9 @@ while (<STDIN>) { chomp; if (/^You mix ([a-z ]+?) and ([a-z ]+?) and create a quantity of (.+?)\.?$/) { - addCombo($1, $2, $3); + addCombo($3, $1, $2); } elsif (/^([a-zA-Z0-9]+)#([a-z ]+)\+([a-z ]+)=([a-z ]+)$/) { - addCombo($2, $3, $4); + addCombo($4, $2, $3); } elsif (/^(You slip up and fumble your attempt.)/) { $fumble = 1; } @@ -160,7 +160,11 @@ foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) { printf "%-35s = ", $min1." + ".$min2; my $n = 0; - foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) { + foreach my $res (sort { + $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} + || + $a cmp $b + } keys %{$final{$min1}{$min2}}) { print $res."[".$final{$min1}{$min2}{$res}."] "; $n++; }