in reply to Re: Re: [perlre/perlgolf] Golf: Sunset strip!
in thread [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please
Update: Fixed the data and the code above.
Okay. All my non-prioritised items started with lower case, so they got sorted last. D'oh!
Evidence for the defence.
#! perl -sw use strict; # 1 2 3 4 5 6 +7 8 #234567890123456789012345678901234567890123456789012345678901234567890 +123456789012345 sub by_priority{my$r=qr/^(?:Service|Organisation|FAQ)/;$a cmp$b|($a=~$ +r&-1)+($b=~$r)} 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 the lazy Organisation_2 dog /; print $_,$/ for sort by_priority @stuff; __END__ c:\test>test FAQ_A FAQ_B FAQ_C Organisation_1 Organisation_2 Organisation_3 Services_p Services_q Services_s brown dog fox jumps lazy over quick the the c:\test>
|
|---|