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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cutting repetition in POE coding
by BrowserUk (Patriarch) on Nov 26, 2005 at 12:06 UTC | |
Re: Cutting repetition in POE coding
by robin (Chaplain) on Nov 26, 2005 at 23:26 UTC | |
Re: Cutting repetition in POE coding
by johnnywang (Priest) on Nov 26, 2005 at 20:16 UTC | |
Re: Cutting repetition in POE coding
by nicholasrperez (Monk) on Nov 26, 2005 at 23:29 UTC | |
Re: Cutting repetition in POE coding
by Anonymous Monk on Nov 26, 2005 at 12:14 UTC | |
by halley (Prior) on Nov 26, 2005 at 16:08 UTC | |
Re: Cutting repetition in POE coding
by rcaputo (Chaplain) on Nov 27, 2005 at 17:52 UTC |
Back to
Seekers of Perl Wisdom