Never been a big fan of ST ... it's kinda like a one night stand ... sure it feels good but you feel ashamed afterwards (or so I'm told). Just use temp variables ...

#!/usr/bin/perl use strict; use warnings; my %hash = ( 'foo00' => '12:NY:me@yoi00.com', 'foo01' => '12:NJ:me@yoi01.com', 'foo02' => '12:NV:me@yoi02.com', 'foo03' => '12:AL:me@yoi03.com', 'foo04' => '12:AK:me@yoi04.com', 'foo05' => '12:MD:me@yoi05.com', 'foo06' => '12:MO:me@yoi06.com', 'foo07' => '12:MI:me@yoi07.com', 'foo08' => '12:MA:me@yoi08.com', 'foo09' => '12:CA:me@yoi09.com', ); # create array that looks like this # [ # [ foo00, NY ], # [ foo01, NJ ], # .. # [ foo09, CA ] # ] my @temp; foreach my $key ( keys %hash ) { my @values = split( /:/, $hash{$key} ); push( @temp, [ $key, $values[1] ] ); } # sort array by second element my @sort = sort { $a->[1] cmp $b->[1] } @temp; # roll through sort and use # first element of array as key into hash foreach my $ref ( @sort ) { print "$ref->[0]: $hash{$ref->[0]}\n"; }
So ST is compact but too dense for me (or maybe I'm too dense for ST).

-derby

In reply to Re^2: sort a hash with split values by derby
in thread sort a hash with split values 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.