BUU has asked for the wisdom of the Perl Monks concerning the following question:
Here's the scenario. I have an event handle that, based on certain conditions, should send an event to another session with specific arguments, and then exit the current subroutine. The perl implementation is simple:
My first attempt involved definining a subroutine:
Any bright ideas?
The problem is, I want to do this multiple times, with different conditions and arguments. Obviously I could type this out multiple times, but surely we all agree cut and pasting code is a bad idea. So my question to you is, how can I best achieve this in the smallest amount of code?if( $condition ) { $kernel->post( $s, event => @args ); return; }
My first attempt involved definining a subroutine:
This is nice and short, as it should be, but it lacks the temrinating 'return' and I can not devise a good method to make the sub EVENT do it.sub EVENT { $kernel->post( shift, event => @_ ) }; #basically ... EVENT $session, "argh" if $condition;
Any bright ideas?
Back to
Seekers of Perl Wisdom