KILNA has asked for the wisdom of the Perl Monks concerning the following question:
But really, the only thing that's significant is the calls to foo() and bar(). The dies are just stating information that's already there, if we give the block some context. I am pondering writing a source filter so that I can wrap every statement with an '|| die "$statement returned false!"', but this seems really dirty. Ideally I'd like a syntax like:{ foo() || die "foo() didn't return true"; bar() || die "bar() didn't return true"; ... and so on }
So, to emulate the above example:every { block of statements } run { block to be run after each statement in 1st block }
Am I crazy for even wanting something like this? Is there something out there that can accomplish the goals of syntactic simplicity (not burdening the straight sequence of statements with extra baggage) while still giving the ability to do something after each statement?every { foo(); bar(); ... } run { my $command = shift; # String representation of statement my $result = shift; # What the statement returned die "Command $command did not return true!" unless $result; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Doing the same thing after each statement in a block...?
by ikegami (Patriarch) on May 19, 2009 at 20:40 UTC | |
|
Re: Doing the same thing after each statement in a block...?
by DStaal (Chaplain) on May 19, 2009 at 20:30 UTC | |
|
Re: Doing the same thing after each statement in a block...?
by morgon (Priest) on May 19, 2009 at 22:10 UTC |