in reply to Anonymous Thingies

The most obvious uses have already been pointed out, but I'd like to mention one other: closures.

When an anonymous subroutine holds references to a lexically scoped variable, and a reference to the subroutine is kept after the lexical variables pass out of scope, the result is a closure: those lexical variables are now held only by that anonymous sub. You can create an entire object system this way, if you are so inclined, or you can just pass around coderefs that hold state. This allows a routine to have a persistent local variable that keeps its value between calls. Further, if the code that creates the closure gets called multiple times, it creates multiple closures -- each with its own variables. Unfortunately, I don't have a really good example of this to give you, because all the nodes I've posted so far that use this technique are obfuscated and so don't make very clear examples. Sorry about that. But it is possible to use this same effect in much cleaner, nicer, better-looking, and more maintainable code. Maybe someone else can give you a good legible example.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/