Lady_Aleena has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I hope you had a good weekend.
The following is a sort that I wrote for my Twitter lists that is not sorting as I had hoped. The rules of the sort are being followed, however, the items that match the individual rules are not being sorted against each other. I have not figured out how to sort the "groups".
I will be putting the sort into a subroutine. Also, this is partially a sanity check.
#!/usr/bin/perl use strict; use warnings FATAL => qw( all ); use lib '../files/perl/lib'; use Base::Data qw(data_file get_hash); use Base::Nifty qw(my_sort); use Twitter qw(twitter_accounts); my $link = "https://twitter.com/#!"; my %lists; for my $account (twitter_accounts) { my $account_list_file = data_file("Twitter/users/$account","lists.tx +t"); if (-s $account_list_file) { my %sublists = get_hash( file => $account_list_file, headings => [qw(id slug name user members_count members_change s +ubscribers_count subscribers_change status)], ); for (keys %sublists) { next if $sublists{$_}{status} ne 'owner'; $lists{$_} = $sublists{$_}; } } } my @networks = qw(ABC CBS FOX NBC SyFy TNT USA); my $network_string = join('|',@networks); for my $list (sort { if ($a->{user} =~ /LadyAleena_($network_string|TV)/ && $a->{name} !~ + /TV/) { return -1 } elsif ($b->{user} =~ /LadyAleena_($network_string|TV)/ && $b->{name} + !~ /TV/) { return 1 } else { if ($a->{user} =~ /LadyAleena_($network_string)/ && $a->{name} =~ +/TV shows$/) { return -1 } elsif ($b->{user} =~ /LadyAleena_($network_string)/ && $b->{name} +=~ /TV shows$/) { return 1 } else { if ($a->{user} eq 'LadyAleena_TV' && $a->{name} eq 'Premium TV s +hows') { return -1 } elsif ($b->{user} eq 'LadyAleena_TV' && $b->{name} eq 'Premium T +V shows') { return 1 } else { if ($a->{user} eq 'LadyAleena_TV' && $a->{name} eq 'TV shows') + { return -1 } elsif ($b->{user} eq 'LadyAleena_TV' && $b->{name} eq 'TV show +s') { return 1 } else { if ($a->{user} eq 'LadyAleena_TV' && $a->{name} eq 'TV netwo +rks') { return -1 } elsif ($b->{user} eq 'LadyAleena_TV' && $b->{name} eq 'TV ne +tworks') { return 1 } else { if ($a->{user} eq 'Lady_Aleena' && $a->{name} =~ /(Comedia +ns|Musicians)/) { return -1 } elsif ($b->{user} eq 'Lady_Aleena' && $b->{name} =~ /(Come +dians|Musicians)/) { return 1 } else { if ($a->{user} eq 'Lady_Aleena' && $a->{name} =~ /(Horro +r|Science fiction)/) { return -1 } elsif ($b->{user} eq 'Lady_Aleena' && $b->{name} =~ /(Ho +rror|Science fiction)/) { return 1 } else { if ($a->{user} eq 'Lady_Aleena' && $a->{name} eq 'Ripl +ey\'s & Guinness') { return -1 } elsif ($b->{user} eq 'Lady_Aleena' && $b->{name} eq 'R +ipley\'s & Guinness') { return 1 } else { if ($a->{user} eq 'LadyAleena_home') { return -1 } elsif ($b->{user} eq 'LadyAleena_home') { return 1 } else { if ($a->{user} eq 'Lady_Aleena' && $a->{name} =~ / +(Followers' businesses|List subscribers)/) { return -1 } elsif ($b->{user} eq 'Lady_Aleena' && $b->{name} = +~ /(Followers' businesses|List subscribers)/) { return 1 } else { my_sort($a->{name},$b->{name},'article'); } } } } } } } } } } } values %lists) { local $\ = "\n"; my $name = $list->{name}; my $user = $list->{user}; print "$name ($user)"; }
Results
Doctor Who (LadyAleena_TV) Hercules & Xena (LadyAleena_TV) Highlander (LadyAleena_TV) Star Trek (LadyAleena_TV) Leverage (LadyAleena_TNT) Body of Proof (LadyAleena_ABC) In Plain Sight (LadyAleena_USA) Necessary Roughness (LadyAleena_USA) seaQuest (LadyAleena_NBC) Sanctuary (LadyAleena_SyFy) Fairly Legal (LadyAleena_USA) White Collar (LadyAleena_USA) MythBusters (LadyAleena_TV) Painkiller Jane (LadyAleena_SyFy) Jericho (LadyAleena_CBS) Harry's Law (LadyAleena_NBC) Chuck (LadyAleena_NBC) Grimm (LadyAleena_NBC) Once Upon a Time (LadyAleena_ABC) Primeval (LadyAleena_TV) Stargate (LadyAleena_SyFy) Eureka Warehouse13 Alphas (LadyAleena_SyFy) No Ordinary Family (LadyAleena_ABC) Buffy & Angel (LadyAleena_TV) Covert Affairs (LadyAleena_USA) Studio 60 (LadyAleena_NBC) Buck Rogers 25th Century (LadyAleena_NBC) Lipstick Jungle (LadyAleena_NBC) Crossing Jordan (LadyAleena_NBC) Law & Order (LadyAleena_NBC) Firefly (LadyAleena_FOX) Advtr of Brisco County Jr (LadyAleena_FOX) Babylon 5 (LadyAleena_TV) Haven (LadyAleena_SyFy) Falling Skies (LadyAleena_TNT) Bones & The Finder (LadyAleena_FOX) The Mercury Men (LadyAleena_SyFy) Andromeda (LadyAleena_SyFy) Burn Notice (LadyAleena_USA) Castle (LadyAleena_ABC) Numb3rs (LadyAleena_CBS) Rizzoli & Isles (LadyAleena_TNT) ER Third Watch Med Invgtn (LadyAleena_NBC) NBC TV shows (LadyAleena_NBC) USA TV shows (LadyAleena_USA) ABC TV shows (LadyAleena_ABC) TNT TV shows (LadyAleena_TNT) CBS TV shows (LadyAleena_CBS) FOX TV shows (LadyAleena_FOX) Premium TV shows (LadyAleena_TV) TV shows (LadyAleena_TV) TV networks (LadyAleena_TV) Musicians (Lady_Aleena) Comedians (Lady_Aleena) Science fiction (Lady_Aleena) Horror (Lady_Aleena) Ripley's & Guinness (Lady_Aleena) Utilities (LadyAleena_home) Groceries (LadyAleena_home) Software (LadyAleena_home) Stores (LadyAleena_home) List subscribers (Lady_Aleena) Followers' businesses (Lady_Aleena)
Have a cookie and a very nice day!
Lady Aleena
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pointers needed to tweak a sort
by ambrus (Abbot) on Jul 02, 2012 at 21:33 UTC | |
by Lady_Aleena (Priest) on Jul 02, 2012 at 21:55 UTC | |
by Lady_Aleena (Priest) on Jul 04, 2012 at 05:40 UTC | |
by ambrus (Abbot) on Jul 05, 2012 at 14:40 UTC |
Back to
Seekers of Perl Wisdom