ff has asked for the wisdom of the Perl Monks concerning the following question:
but the variables were processed in alphabetical order, e.g.:foreach ( sort gs::long_strings_first(), @$raw_hash_keys_ar ) { #do_stuff; } package gs; sub long_strings_first { return ( 0 ) unless defined $b; length $b <=> length $a || lc $b cmp lc $a }
When I apply the logic directly (within braces following 'sort') I get the desired 'longest to shortest' sort of the terms.'All-American Residential Framing' 'Builders Assistant' 'Colson Plumbing' 'Electric Systems' 'Greenways' 'P & L Lighting' 'Regis Co.' 'Robert E. Matthews'
foreach ( sort { length $b <=> length $a || lc $b cmp lc $a } @$raw_hash_keys_ar ) { # do stuff; } # Processed as: 'All-American Residential Framing' 'Robert E. Matthews' 'Builders Assistant' 'Electric Systems' 'Colson Plumbing' 'P & L Lighting' 'Regis Co.' 'Greenways'
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing $a and $b of 'sort' across package boundaries
by ikegami (Patriarch) on Jun 06, 2005 at 19:20 UTC | |
by davidrw (Prior) on Jun 06, 2005 at 19:26 UTC | |
by ikegami (Patriarch) on Jun 06, 2005 at 19:34 UTC | |
by davidrw (Prior) on Jun 06, 2005 at 19:49 UTC | |
by ikegami (Patriarch) on Jun 06, 2005 at 20:54 UTC | |
by ff (Hermit) on Jun 06, 2005 at 19:28 UTC | |
|
Re: Accessing $a and $b of 'sort' across package boundaries
by salva (Canon) on Jun 06, 2005 at 19:42 UTC | |
|
Re: Accessing $a and $b of 'sort' across package boundaries
by ambrus (Abbot) on Jun 06, 2005 at 19:31 UTC |