On Sat, 2002-04-20 at 14:33, Me wrote: > [2c. What about ( data) or (ops data) normally means non-capturing, > ($2 data) captures into $2, ($foo data) captures into $foo?]
Very nice (but, I assume you meant {$foo data})! This does add another special case to the regexp parser's handling of "$", but it seems like it would be worth it. Makes me think of the even slightly hairier: {&foo data} or even more hair-full: {&{$foo} data} for references. Where you capture into the usual positional, and then invoke foo with the variable as parameter. Would be pretty nice closure-wise: sub match_with_alert($re,$id,$ops,$fac,$pri) { openlog $id,$ops,$fac; my $alert = sub ($match) { syslog $pri, "Matched regexp: $match"; } return study /{&{$alert} $re}/; } my $m = match_with_alert('ROOT login',$0,0,LOG_USER,PRI_CRIT); for <> -> $_ { /$m/ } That would certainly be a handy thing that would set Perl apart from the pack of advanced regexp languages that don't support closures.... Some other things come to mind as well, but I'm not sure how evil they are. For example: sub decrypt($data is rw) { $data = rot13($data); } print "The secret message is: ", /^Encrypted: {&decrypt .*}/, "\n";