in reply to [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please

This looks like production code, so I'll assume you want not golfed code, but better abstraction. And it is sort of expensive, so you might want to use a Schwartzian Transform.
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.

  • Comment on Re: [perlre/perlgolf] Golf this: return -1 or return +1 on regexp subroutine please
  • Download Code

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

    Looks more like an obfu than the requested golf.

    Where does the @match array come from?


    Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy