in reply to Sort by distance

Two questions: Where, and how, do you define @zip_dist? It's hard to figure out what the problem with a sort is if we can't see the data that's being sorted.

And number 2: What are you trying to do in line #22? Whatever it is, something should probably have a different name. (You've got @km and $km, and I think you are trying to use them as separate variables. Which can be done, but it's going to confuse you, your maintainer, or perl. Or all three.)

Replies are listed 'Best First'.
Re^2: Sort by distance
by pglinx (Acolyte) on May 27, 2009 at 14:23 UTC
    The section shown as the problem was nothing more then an attempt at sorting but causes the entire database to output with km equaling 0 I probably should have asked the question leaving that part out. I eliminated thing that have to do with count and other funtions to make it more brief and example.

      Well, you eliminated too much: The example above doesn't have enough information to answer your question.

        Here is the entire code that works but I need to sort by km
        print " </td> <TD VALIGN=TOP WIDTH=350 style=\"font-family: arial; font-size: 12px;\ +"> <IMG SRC=\"\" BORDER=0 ALT=\"\"> <BR>Listings Found In Radius ( $count ) <div class=\"scrollbox\"> <font face=arial size=2>\n"; $count = 0; open(FILE, "herbalarea.pl") || die "I can't open that because: $!\ +n"; while(<FILE>) { chop; @all = split(/\n/); foreach $line (@all) { local() = split(/ /, $line); $lat2 = $hStoreLatitude; $lon2 = $hStoreLongitude; $lat1 = $lat1a; $lon1 = $lon1a; # Notice the 90 - latitude: phi zero is at the North Pole. @L = (deg2rad($lat1), deg2rad(90 - $lon1)); @T = (deg2rad($lat2), deg2rad(90 - $lon2)); $km = great_circle_distance(@L, @T, 6378); if ($km < $distance) { $match = 1; $count ++; $area = ""; $area1 = ""; $area2 = ""; $rounded = sprintf("%.1f", $km); print " <table border=0 width=240 height=105 cellpadding=15 cellspacing=0 back +ground=\"\"> <tr> <td style=\"font-size: 11px; color: #5D5D5D;\"> Store # <A HREF=\"javascript:change1('pic1','image$count')\">$area</A> +<BR>\n"; print "<div class=\"book\"><A HREF=\"\" target=_parent>Book Your Free +Consultation.</a> - KM $rounded</div></A></td> </tr> </table> \n";