I couldn't get your test package to work, so I made a little
test script of my own which is more "straight-forward",
and some more "realistic data".
It sorts as advertised.
I'm not real good at dereferencing but I worked out a little
routine that will print out the sort results, and will dereference
the arrays and hashes that are returned automatically.
I hate it when you print out results, and get HASH019283474
or ARRAY1234234.
my LOH.pm test
##############################################
#!/usr/bin/perl use warnings; use strict; use Sort::LOH; my @SAMPLE_DATA = ( {ID => "a1 a", F_NAME => "asd b1 b", L_NAME => "ggfsdfc1 c" +, STREET => "5", {ID => "a2 b", F_NAME => "zxczxc b2 c", L_NAME => "sdvwevc2 d" +, STREET => "2", {ID => "a3 c", F_NAME => "cdaer b3 d", L_NAME => "sdfwbbfc3 e +", STREET => "4", {ID => "a4 d", F_NAME => "aaaa asdafsdf b4 e", L_NAME => "asdferwv c6 + b", STREET => "4", {ID => "a5 e", F_NAME => "vdasdvqd43 b5 f", L_NAME => "aaaaa c5 a" +, STREET => "1", {ID => "a6 f", F_NAME => "eee ecasd b6 a", L_NAME => "asdferwv c6 + b", STREET => "6", ); my @WACKY_DATA = ( {ID => "a1 a", NAMES => ["BOB", "ELLEN"], STREET => "2nd Ave.", ADDRESS => "2", CITY => "Detroit"}, {ID => "a2 b", NAMES => ["SUE", "ROB"], STREET => [home=>"Birdview + Lane",vacation=>"Lake George Circle"], ADDRESS => [home=>"9",vacation=>"20"], CITY => "Lake George"}, {ID => "a3 c", NAMES => ["JOHN", "JANE"], STREET => "1rst", ADDRESS => "1045", CITY => "Lansing"}, {ID => "a4 d", NAMES => ["LOUIS", "ELLA"], STREET => "Silvery Lane", ADDRESS => "13", CITY => "Macon"}, {ID => "a5 e", NAMES => ["RICK", "MARK"], STREET => "Plaza Center", ADDRESS => "9", CITY => "Albany"}, {ID => "a6 f", NAMES => ["IGNATZ", "CRAZY"],STREET => "6th Street", ADDRESS => "66", CITY => "Wackoville"} ); ###################################################################### +######## my $lohSorter = Sort::LOH->new(\@SAMPLE_DATA); my @sorted = $lohSorter->sortMe(["STREET"]); #print "@sorted\n"; foreach my $href(@sorted){ print "########################################\n"; foreach my $key (keys %$href){ print "$key ---> ${$href}{$key}\n"; } print "########################################\n"; } ###################################################################### +######## print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +\n"; ###################################################################### +### my $lohSorter1 = Sort::LOH->new(\@WACKY_DATA); my @sorted1 = $lohSorter1->sortMe(["ADDRESS"]); #print "@sorted1\n"; foreach my $href1(@sorted1){ # print Dumper(%$_); print "########################################\n"; foreach my $key (keys %$href1){ if (${$href1}{$key} =~ /ARRAY/) {print "$key --->@{${$href1}{$key}}\n"} elsif (${$href1}{$key} =~ /HASH/) {print "$key --->${${$href1}{$key}}\n"} else {print "$key ---> ${$href1}{$key}\n"} } print "########################################\n"; }

In reply to Re: Sort::LOH by zentara
in thread Sort::LOH by ignatz

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.