http://www.perlmonks.org?node_id=11104191


in reply to Sorting on identical values

A module (List::SomeUtils) can make this easy.
>type slugger.pl use strict; use warnings; use List::SomeUtils qw(sort_by); use Data::Dumper; my @strings = ( "http://myurl.com/search/stringA?SomeMoreStuffA", "http://myurlA.com/search/stringB?SomeMoreStuffB", "http://myurlB.com/search/stringC?SomeMoreStuffX", "http://myurlC.com/search/stringA?SomeMoreStuffXYZ", "http://myurl.com/search/stringZ?SomeMoreStuffZZZ", ); my @sorted_strings = sort_by {/search(.+)\?/;$1} @strings; print Dumper(\@sorted_strings); >perl slugger.pl $VAR1 = [ 'http://myurl.com/search/stringA?SomeMoreStuffA', 'http://myurlC.com/search/stringA?SomeMoreStuffXYZ', 'http://myurlA.com/search/stringB?SomeMoreStuffB', 'http://myurlB.com/search/stringC?SomeMoreStuffX', 'http://myurl.com/search/stringZ?SomeMoreStuffZZZ' ]; >
Bill