in reply to [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please
77.
1 2 3 4 5 6 7 + 1234567890123456789012345678901234567890123456789012345678901234567890 +1234567 sub by_priority{my$r=qr/^(?:Service|Organisation|FAQ)/;($a=~$r&&-1)+($ +b=~$r)}
Update: As anon. below points out, I hadn't read the spec properly, so... for a less desireable 89 85 88. Instead of Sunset strip, thats two fat ladies.
# 1 2 3 4 5 6 +7 8 #234567890123456789012345678901234567890123456789012345678901234567890 +123456789012345678 sub by_priority{my$r=qr/^(?:Service|Organisation|FAQ)/;($a=~$r&&-1)+($ +b=~$r)||$a cmp$b;}
Test code and results (Hopefully I didn't try a step to far this time.)
#! perl -sw use strict; # 1 2 3 4 5 6 +7 8 #234567890123456789012345678901234567890123456789012345678901234567890 +12345678901234567 sub by_priority{my$r=qr/^(?:Service|Organisation|FAQ)/;($a=~$r&&-1)+($ +b=~$r)||$a cmp$b} my @stuff = qw/ the Services_s FAQ_A quick FAQ_C Organisation_3 brown FAQ_B fox Services_p jumps Services_q Over Organisation_1 A lazy Organisation_2 dog /; sub shufl (\@) { my $r=pop; $a = $_ + rand @{$r} - $_ and @$r[$_, $a] = @$r[$a, $_] for (0..$#{$r}); } shufl @stuff; print $_,$/ for sort by_priority @stuff; __END__ c:\test>test FAQ_A FAQ_B FAQ_C Organisation1 Organisation2 Organisation3 Servicesp Servicesq Servicess A Over brown dog fox jumps lazy quick the c:\test>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: [perlre/perlgolf] Golf: Sunset strip!
by Anonymous Monk on Oct 31, 2002 at 23:55 UTC | |
by BrowserUk (Patriarch) on Nov 01, 2002 at 00:28 UTC | |
|
Re: Re: [perlre/perlgolf] Golf: Sunset strip!
by Anonymous Monk on Oct 31, 2002 at 23:16 UTC |