use strict; use warnings; ... my $sql = qq| SELECT ID, tutorID, Latitude, Longitude, City, State, Zipcode FROM $table_tzips WHERE Zipcode IS not NULL |; my $sth = $dbh->prepare($sql); my %closest; $sth->execute(); while (my $tzips = $sth->fetchrow_hashref()) { my $tutorID = $tzips->{tutorID}; my $dist = calculate_distance( $clong, $clat, $tzips->{Longitude}, $tzips->{Latitude} ); next if $closest{$tutorID} && $closest{$tutorID}{dist} <= $dist; $closest{$tutorID} = { ID => $tutorID, tzipID => $tzips->{ID}, Dist => $dist, City => $tzips->{City}, State => $tzips->{State}, Zipcode => $tzips->{Zipcode}, }; } my @report_fields = qw( tzipID ID Dist City State Zipcode ); for my $tutor ( sort{ $a->{dist} <=> $b{dist} } values(%closest) ) { print(join(', ', @{$tutor}{@report_fields}), "\n"); }

In reply to Re: sorting an array of hashes and removing duplicates by ikegami
in thread sorting an array of hashes and removing duplicates by jmfees

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.