[Mpls-pm] Interesting RegEx Problem

Ian Malpass ian at indecorous.com
Mon Sep 19 10:14:10 PDT 2005


On Mon, 19 Sep 2005, Joshua ben Jore wrote:

> I've been hoping someone would mention List::Util::first.
>
> use List::Util 'first';
> $matching_expression = first { $text =~ $_ } @candidate_expressions

Problem with that is that you get a regex out at the end, which you then 
need to hack on to make useful.

List::Util has useful stuff in it, and if I was doing the list 
manipulations it covers frequently in a piece of code I'd probably use it, 
but it seems a shame to require the module just to get a for loop with a 
break in it.

I also don't find the above syntax all that clear. Especially if the use 
and the call to first() are separated by a lot of code. The name 'first' 
is fairly self-explanatory, I suppose, but it's not a standard perl 
function, which might fox the unwary.

All comes down to philosophy and house style, in the end. And 
documentation. There is, after all, more than one way to do it.

Ian

-
---------------------------------------------------------------------------

The soul would have no rainbows if the eyes held no tears.

Ian Malpass
<ian at indecorous.com>


More information about the Mpls-pm mailing list