in reply to Get the Smallest Number
I'm not sure what you desire. The code below allows for the possibility that multiple lines could have this same "min number at the end of the line, in that case, below code prints them all.
Update: This ~0 statement was just a way to generate a huge number (one's complement of 0). From what I see, any huge number would do. I was surprised that this wasn't -1. For this code it didn't make any difference.#!/usr/bin/perl -w use strict; my $add_loc = { '4' => 'Store 1|100 Main Street|55.06', '3' => 'Store 2|210 East Main Street|0.00', '2' => 'Store 3|301 West Main Street|11.23', '6' => 'Store 5|501 SW Main Street|0.00', '8' => 'Store 8|999 Some Street|0.00', }; my $max_num = (~0); foreach my $min_key (sort by_last_hash_value (keys %$add_loc)) { my $last_num_in_string = (split(/[|]+/,$add_loc->{$min_key}) )[-1]; last if ( $last_num_in_string > $max_num); print "min string is: $add_loc->{$min_key}\n"; print " last value in that string is: ", $last_num_in_string, "\n"; $max_num = $last_num_in_string; } sub by_last_hash_value { my $a_num = (split(/|/,$add_loc->{$a}))[-1]; my $b_num = (split(/|/,$add_loc->{$b}))[-1]; $a_num <=> $b_num } __END__ min string is: Store 8|999 Some Street|0.00 last value in that string is: 0.00 min string is: Store 5|501 SW Main Street|0.00 last value in that string is: 0.00 min string is: Store 2|210 East Main Street|0.00 last value in that string is: 0.00
|
|---|