Your problem statement doesn't compile, so I just wrote some code assuming that 'add_loc' was a pointer to hash.

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.

#!/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
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.

In reply to Re: Get the Smallest Number by Marshall
in thread Get the Smallest Number by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.