Here's the test script (as if you cared) that I'm using on this sucka:
package Sort::Test::LOH_test; use strict; use base qw(Test::Unit::TestCase); my @SAMPLE_DATA = ( {ID => "a1 a", F_NAME => "asd b1 b", L_NAME => "ggfsdf +c1 c", STREET => "5", ADDRESS => "2", CITY => "f1 f"}, {ID => "a2 b", F_NAME => "zxczxc b2 c", L_NAME => "sdvwevc +2 d", STREET => "2", ADDRESS => "9", CITY => "f2 a"}, {ID => "a3 c", F_NAME => "cdaer b3 d", L_NAME => "sdfwbbf + c3 e", STREET => "4", ADDRESS => "045", CITY => "f3 b"}, {ID => "a4 d", F_NAME => "aaaa asdafsdf b4 e", L_NAME => "asdferw +v c6 b", STREET => "4", ADDRESS => "1.3", CITY => "f4 c"}, {ID => "a5 e", F_NAME => "vdasdvqd43 b5 f", L_NAME => "aaaaa c +5 a", STREET => "1", ADDRESS => "9", CITY => "f5 d"}, {ID => "a6 f", F_NAME => "eee ecasd b6 a", L_NAME => "asdferw +v c6 b", STREET => "6", ADDRESS => "8.8", CITY => "f6 e"} ); my @WACKY_DATA = ( {ID => "a1 a", NAMES => ["BOB", "ELLEN"], STREET => "5", + ADDRESS => "2", CITY => "f1 f"}, {ID => "a2 b", NAMES => ["SUE", "ROB"], STREET => [@SAMPLE_DAT +A], ADDRESS => "9", CITY => "f2 a"}, {ID => "a3 c", NAMES => ["JOHN", "JANE"], STREET => "4", + ADDRESS => "045", CITY => "f3 b"}, {ID => "a4 d", NAMES => ["LOUIS", "ELLA"], STREET => "4", + ADDRESS => "1.3", CITY => "f4 c"}, {ID => "a5 e", NAMES => ["RICK", "MARK"], STREET => "1", + ADDRESS => "9", CITY => "f5 d"}, {ID => "a6 f", NAMES => ["IGNATZ", "CRAZY"],STREET => "6", + ADDRESS => "8.8", CITY => "f6 e"} ); sub test_lohsorter { my $self = shift; my $lohSorter = Sort::LOH->new(\@SAMPLE_DATA); my @sorted = $lohSorter->sortMe(["L_NAME", "F_NAME"]); $self->assert($sorted[0]{CITY} eq "f5 d", "Test ALPHA on L_NAME"); $self->assert($sorted[2]{CITY} eq "f6 e"); $self->assert($sorted[5]{CITY} eq "f2 a"); @sorted = $lohSorter->sortMe(["-L_NAME", "F_NAME"], "Test inverted + prime ALPHA with sub not inverted on L_NAME"); $self->assert($sorted[4]{CITY} eq "f6 e"); @sorted = $lohSorter->sortMe(["STREET n"]); $self->assert($sorted[1]{CITY} eq "f2 a", "Test ALPHA on STREET"); @sorted = $lohSorter->sortMe(["-STREET n"]); $self->assert($sorted[1]{CITY} eq "f1 f", "Test inverted ALPHA on +STREET"); @sorted = $lohSorter->sortMe(["ADDRESS"]); $self->assert($sorted[0]{CITY} eq "f3 b", "Test ALPHA on ADDRESS") +; # Test one row to make sure that all the fields are intact. $self->assert($sorted[1]{ID} eq "a4 d"); $self->assert($sorted[1]{F_NAME} eq "aaaa asdafsdf b4 e"); $self->assert($sorted[1]{L_NAME} eq "asdferwv c6 b"); $self->assert($sorted[1]{STREET} eq "4"); $self->assert($sorted[1]{ADDRESS} eq "1.3"); $self->assert($sorted[1]{CITY} eq "f4 c"); $self->assert($sorted[2]{CITY} eq "f1 f"); $self->assert($sorted[3]{CITY} eq "f6 e"); $self->assert($sorted[4]{CITY} eq "f2 a"); $self->assert($sorted[5]{CITY} eq "f5 d"); @sorted = $lohSorter->sortMe(["-ADDRESS n"]); $self->assert($sorted[0]{CITY} eq "f3 b", "Test inverted NUMERIC o +n ADDRESS"); $self->assert($sorted[3]{CITY} eq "f6 e"); $self->assert($sorted[4]{CITY} eq "f1 f"); $self->assert($sorted[5]{CITY} eq "f4 c"); } sub test_factory { my $self = shift; my @sorted = Sort::LOH->static(["L_NAME", "F_NAME"], \@SAMPLE_DATA +); $self->assert($sorted[0]{CITY} eq "f5 d", "Test of factory method +with ALPHA on L_NAME"); $self->assert($sorted[2]{CITY} eq "f6 e"); $self->assert($sorted[5]{CITY} eq "f2 a"); } sub test_wacky_data { my $self = shift; my $sorter = Sort::LOH->new(\@WACKY_DATA); my @sorted = $sorter->sortMe(["-ID", "F_NAME"]); $self->assert($sorted[0]{CITY} eq "f6 e", "Wacky data test with re +verse ALPHA on ID and bad field call."); } 1;
()-()
 \"/
  `                                                     

In reply to Re: Sort::LOH by ignatz
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.