[OT] Should exist / does exist?

Andy Armstrong andy at hexten.net
Wed Dec 6 20:33:49 GMT 2006

(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;

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