[OT] Should exist / does exist?

Adriano Ferreira a.r.ferreira at gmail.com
Thu Dec 7 09:34:03 GMT 2006


On 12/6/06, Andy Armstrong <andy at hexten.net> wrote:
> (I've searched CPAN for this but either I'm using the wrong search
> terms or it doesn't exist)
>
> I like using closures to emulate Ruby blocks like this:
>
> $db->withQuery(sub {
>     my $row = shift;
>     # Do stuff with $row
> });
>
> In this (hypothetical) case the anon closure would be called for
> every row in the results of a database query. This is how Ruby
> handles most of its looping constructs.
>
> This works already but it'd be even nicer to be able to write
>
> $db->withQuery(ROW => sub {
>      my $row = shift;
>      if ($row->{'some_value'} > $some_limit) {
>          last ROW;
>      }
> });

That made me curious: what is the Ruby expression to do that? IMO it
looks like Ruby must have the same unsolved issue. Or am I wrong?

> In other words it'd be nice if the callback closure had something
> approaching normal loop semantics: next, redo and last would DWIM.
>
> Have I missed a module that already does this?
>
> You can fake it at the moment using die / eval and could probably
> implement it properly with either a source filter or by decompiling
> and munging the closure.
>
> Before I have a play with it has anyone already been this way?
>
> --
> Andy Armstrong, hexten.net
>
>


More information about the london.pm mailing list