Your skill will accomplish
what the force of many cannot
Re: Making my own control flow structureby Corion (Patriarch)
|on Oct 09, 2006 at 12:25 UTC
In Perl, there are no custom-made control flow statements like in Lisp, and there are no convenient ways to dump the statements not executed. You can fudge something like it by using eval, in the following way:
Which you can then clumsily use like this:
There are a lot of drawbacks to this, as you can't conveniently pass variables into the if block for example. The upside is that the format of the code and the comments will still be output.
The second alternative would be to pass a real code block and then use B::Deparse to get at a string representation:
Which you can then use like this, the clumsyness gets pushed into a different corner here:
This has the advantage of passing around closures and hence working with local and lexical variables. It has the disadvantage of relying on B::Deparse which doesn't always give you back what you wrote but only gives you back the Artists Rendition.