+my $addresses = $old{billship} ? 'addresses' : 'address';
+my $show_radio = 0;
+my $failed = 0; # true if standardization returned no addresses
+
+my @prefixes = ('');
+
+if ( $old{same} ) {
+
+ # Then there are bill and ship addresses and they're the same. Treat
+ # bill_error as a failure, and let the user accept or reject the whole
+ # standardization.
+
+ @prefixes = ('bill_');
+ $failed = 1 if $new{'bill_error'};
+
+} elsif ( $old{billship} ) {
+
+ # There are separate bill and ship addresses. Treat error in both as a
+ # failure. Otherwise, at least one of them has a choice between entered
+ # and standardized address, so let the user choose.
+
+ @prefixes = ('bill_', 'ship_');
+ if ( $new{'bill_error'} and $new{'ship_error'} ) {
+ $failed = 1;
+ } else {
+ $show_radio = 1;
+ }
+
+} else {
+
+ # There are no bill/ship addresses (this is used for package locations).
+ # Treat like the first case but without the bill_ prefix.
+ @prefixes = ('');
+ $failed = 1 if $new{'error'};
+
+}
+
+my $census_error = $new{'census_error'}; # seems to be unused
+my $is_error = $census_error || grep { $new{$_.'error'} } @prefixes;