talexb has asked for the wisdom of the Perl Monks concerning the following question:

I have started to take a hard look at POE, using merlyn's excellent Column 41 as a learning tool.

I'm making progress, but part of the Perl syntax has me confused. Specifically, in one routine merlyn gets the kernel object using my $kernel = $_[KERNEL]; (Line 38) and then uses it with $kernel->yield("ready", "looping"); (Line 48) which is fine, except I'm not familiar with this use of $_.

Later on in the example, in another routine, he skips that nicety and just says $_[KERNEL]->yield("ready", "child done"); (line 65). I'm familiar with @_, but I'm unsure about where $_ comes from in that context.

Can someone elighten me? Thanks.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Update 1: Fixed broken link; thanks zentara

Replies are listed 'Best First'.
Re: POE and $_[KERNEL]
by gellyfish (Monsignor) on Sep 06, 2005 at 18:00 UTC

    The $_[KERNEL] is just an indexed access to @_ using the predefined constant KERNEL - using the constants like this allows for one thing POE to not have to document explicitly the order in which all of the arguments are passed to the method.

    Update: frodo72 pointed me to http://poe.perl.org/?POE_FAQ/calling_convention that explains this rather nicely.

    /J\

      D'Oh! Of course, $_[some index here] is just Perl accessing the @_ array. And I already know that KERNEL is a constant -- defined as a simple function in POE::Session.

      Sorry, that was a somewhat lame question -- for some reason I thought it was doing some wonderfully dark magic that wasn't even in the Camel. Phew.

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: POE and $_[KERNEL]
by zentara (Cardinal) on Sep 07, 2005 at 09:47 UTC
    I think your link to Merlyn's Column 41 is broken. It needs an href not an [id://

    I'm not really a human, but I play one on earth. flash japh