Hi skins96,

A couple of comments:

  1. You have a stray "<br>" in your code.
  2. You might want to use Data::Dumper, to display intermediate results.
  3. You probably want to put my @data = (); outside of your loop, so it stays in scope afterwards; I'm sure this was causing you some headaches (which Data::Dumper will often help you catch quickly).

In order to see what what going on, I added some debugging to your program:

#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; # use Lingua::EN::NameCase qw( nc ); #Where the files are located... my $Location = 'z:/bpermits/data2007/test/marchpermits.txt'; my $OutFile = 'z:/bpermits/data2007/test/output.txt'; # Debugging -- I don't have a Z: drive :) (and $OutFile isn't used) $Location = "./m.txt"; #Open the files...... open(PERMSIN, $Location) or die "unable to open $Location: $!"; #Read in the file, using a loop........ my @columns = qw( Permit_Number Street_Number Street_Prefix Street_Name Street_Suffi +x Lot Block Issue_Date Proposed_Use_Code Permission_To_Code Square_Feet Estimated_Cost Units Subdivision Zoning Contractor_Name Contractor +_Add1 Contractor_Add2 Contractor_City Contractor_State Contractor_Zip Contractor_Phone1 Contractor_Phone2 Owner_Name Owner_Add1 Owner_Ad +d2 Owner_City Owner_State Owner_Zip Owner_Phone ); # Debugging -- I don't have time to make up all those values :-/ @columns = qw( Permit_Number Street_Number Estimated_Cost ); my @data = (); while( my $line = <PERMSIN> ) { chomp( $line ); # Populate the hash %thisrecord with the column names and # the values from this line. # my @fields = split( /,/, $line ); my %thisrecord = map { $columns[$_] => $fields[$_] } ( 0 .. $#fiel +ds ); push @data, \%thisrecord; } # Debugging -- look at the data before it's sorted print Dumper(\@data), "\n"; print "Unsorted costs: "; map { print $_->{ Estimated_Cost } . ", " } @data; print "\n\n"; # Here's the sort you want! @data = sort { $a->{ Estimated_Cost } <=> $b->{ Estimated_Cost } } @da +ta; # Debugging -- look at the data after it's sorted print Dumper(\@data), "\n"; print "Sorted costs: "; map { print $_->{ Estimated_Cost } . ", " } @data; print "\n\n";

And used a smaller data file (only 3 columns):

1,132,1984 2,93,1748 3,92,1372 4,73,2948 5,83,3105 6,13,1299 7,28,1301 8,35,1305 9,47,1091

This yields the following results, which is what I think you're looking for:

$VAR1 = [ { 'Street_Number' => '132', 'Estimated_Cost' => '1984', 'Permit_Number' => '1' }, { 'Street_Number' => '93', 'Estimated_Cost' => '1748', 'Permit_Number' => '2' }, { 'Street_Number' => '92', 'Estimated_Cost' => '1372', 'Permit_Number' => '3' }, { 'Street_Number' => '73', 'Estimated_Cost' => '2948', 'Permit_Number' => '4' }, { 'Street_Number' => '83', 'Estimated_Cost' => '3105', 'Permit_Number' => '5' }, { 'Street_Number' => '13', 'Estimated_Cost' => '1299', 'Permit_Number' => '6' }, { 'Street_Number' => '28', 'Estimated_Cost' => '1301', 'Permit_Number' => '7' }, { 'Street_Number' => '35', 'Estimated_Cost' => '1305', 'Permit_Number' => '8' }, { 'Street_Number' => '47', 'Estimated_Cost' => '1091', 'Permit_Number' => '9' } ]; Unsorted costs: 1984, 1748, 1372, 2948, 3105, 1299, 1301, 1305, 1091, $VAR1 = [ { 'Street_Number' => '47', 'Estimated_Cost' => 1091, 'Permit_Number' => '9' }, { 'Street_Number' => '13', 'Estimated_Cost' => 1299, 'Permit_Number' => '6' }, { 'Street_Number' => '28', 'Estimated_Cost' => 1301, 'Permit_Number' => '7' }, { 'Street_Number' => '35', 'Estimated_Cost' => 1305, 'Permit_Number' => '8' }, { 'Street_Number' => '92', 'Estimated_Cost' => 1372, 'Permit_Number' => '3' }, { 'Street_Number' => '93', 'Estimated_Cost' => 1748, 'Permit_Number' => '2' }, { 'Street_Number' => '132', 'Estimated_Cost' => 1984, 'Permit_Number' => '1' }, { 'Street_Number' => '73', 'Estimated_Cost' => 2948, 'Permit_Number' => '4' }, { 'Street_Number' => '83', 'Estimated_Cost' => 3105, 'Permit_Number' => '5' } ]; Sorted costs: 1091, 1299, 1301, 1305, 1372, 1748, 1984, 2948, 3105,

It's quite verbose, but I think you can see how I was able to quickly debug it.  Just take out my debugging sections, and you should have a viable solution.

Oh, and by the way, your Perl code is fairly impressive for a self-proclaimed "newbie".  I couldn't wrap my mind around map until I'd been using Perl for quite a while :-)


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Help with sort.... by liverpole
in thread Help with sort.... by skins96

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.