comparison parsealloys.pl @ 49:527d37859f28

Sort the alloy tables more robustly.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 23 Aug 2021 18:19:40 +0300
parents 857333562777
children
comparison
equal deleted inserted replaced
48:857333562777 49:527d37859f28
139 { 139 {
140 print "["; 140 print "[";
141 foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}}) 141 foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}})
142 { 142 {
143 print "\"$min2\" => ["; 143 print "\"$min2\" => [";
144 foreach my $res (sort { $final{$min1}{$min2}{$a} <=> $final{$min1}{$min2}{$b} } keys %{$final{$min1}{$min2}}) { 144 foreach my $res (sort { $a cmp $b} keys %{$final{$min1}{$min2}}) {
145 print "\"$res\" => ".$final{$min1}{$min2}{$res}.", "; 145 print "\"$res\" => ".$final{$min1}{$min2}{$res}.", ";
146 } 146 }
147 print "], "; 147 print "], ";
148 } 148 }
149 print "],\n"; 149 print "],\n";
158 158
159 # Create 'reverse' alloy table 159 # Create 'reverse' alloy table
160 my %restab = (); 160 my %restab = ();
161 foreach my $res (keys %$Materials::matTable) 161 foreach my $res (keys %$Materials::matTable)
162 { 162 {
163 foreach my $min1 (keys %final) 163 foreach my $min1 (sort { $a cmp $b } keys %final)
164 { 164 {
165 foreach my $min2 (keys %{$final{$min1}}) 165 foreach my $min2 (sort { $a cmp $b } keys %{$final{$min1}})
166 { 166 {
167 my $tmp = $final{$min1}{$min2}; 167 my $tmp = $final{$min1}{$min2};
168 168
169 # Do we ignore unstable combinations, e.g. ones with multiple results? 169 # Do we ignore unstable combinations, e.g. ones with multiple results?
170 #if (scalar(keys %$tmp) == 1) 170 #if (scalar(keys %$tmp) == 1)
171 { 171 {
172 foreach my $key (keys %$tmp) 172 foreach my $key (sort { $a cmp $b } keys %$tmp)
173 { 173 {
174 if ($key eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1})) 174 if ($key eq $res && !defined($restab{$res}{$min1}{$min2}) && !defined($restab{$res}{$min2}{$min1}))
175 { 175 {
176 $restab{$res}{$min1}{$min2} = $$tmp{$key}; 176 $restab{$res}{$min1}{$min2} = $$tmp{$key};
177 } 177 }