in reply to [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please
sub by_priority { my @prio = (-1 => $a, 1 => $b); my @prfx = map { (qr/^$_/)x2 } qw(Organization Service FAQ); for(@prfx) { return $prio[0] if $prio[1] =~ /$_/; push @prio, splice @prio, 0, 2; # swap (-1 => $a) and (1 => $b +) } return 0; }
Capture regularities in code, irregularities in data.
Update: oops, thanks BrowserUk. I had used @match rather than @prio at first and forgot to update all locations. Hope it's clear now.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please
by BrowserUk (Patriarch) on Nov 02, 2002 at 07:56 UTC |