# HG changeset patch # User Matti Hamalainen # Date 1425775216 -7200 # Node ID 0adaafd9d6e8c4256253c0382f4e3e44e20854cf # Parent af08f54f0bc6073afea3a0b8a5ed79fc8c90d69c Stabler sorting for text output. diff -r af08f54f0bc6 -r 0adaafd9d6e8 materials/parsealloys.pl --- 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 () { 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++; }