sulfericacid,
I tried something similar once. I reordered the data and then just sorted the string.

However, the problem is that you have to sort ASCII which means that 999 is greater than 1000. The next thing I did was to sprintf my data so that I was comparing 0999 to 1000. That worked. That didn't really sit well though.

It seems to be a lot of mess. Then I discovered LoLs and HoLs and other complex data types. They make it much easier so I'd go with any of the methods below.

Personally I'd store the data as a LoH, but that's just me.

my @data = ( { name => 'Bill Nye', age => 39, town => 'Somewhere in Cali', state => 'Cali', zip => '12345' }, { name => 'Homer Simpson', age => 36, town => 'Springfield', state => undef, zip => '23456' }, { name => 'Barney Rubble', age => 31, town => 'Bedrock', state => 'Cartoon Location', zip => '3456' }, ); print Dumper( sort { $a->{name} cmp $b->{name} } @data );
Other monks will probably tell you that the above is not a good thing because you're storing your hash keys over and over again. However I think it makes it much easier to track your data. It would, of course, be possible to create your own data structure parsing module that had objects and methods for creating, editing and deleting data but there's a ton already out there.


In reply to Re: Re: Complex hash sorting by BigLug
in thread Complex hash sorting 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.