Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Sort::LOH

by zentara (Archbishop)
on Jul 23, 2002 at 19:59 UTC ( [id://184558]=note: print w/replies, xml ) Need Help??


in reply to Sort::LOH

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"; }

Replies are listed 'Best First'.
Re: Re: Sort::LOH
by ignatz (Vicar) on Jul 23, 2002 at 20:17 UTC
    Thanks for that!

    I haven't worked out the best way to sort out tests and stuff under Perl. Right now I just put it in ~perl/site/lib/Sort/Test/LOH_test.pm and calling it with:

    use Test::Unit::TestRunner; my $testrunner = Test::Unit::TestRunner->new(); $testrunner->start("Sort::Test::LOH_test");
    This isn't the best way to do things I'm sure. Part of packaging it up into a standard package install will be getting the tests to run with $> make test. In future I'll have to organize things like that from the start.
    ()-()
     \"/
      `                                                     
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://184558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found