Update: I ended up solving this after asking in CB, and while I was typing these words in. It is an RTFM problem. I thought it would be good to post, since it may help others find the solution faster in the future.

I'm using POE to read from a socket when something is available, then do a bunch of stuff with it. I'm using select_read() to tell me if something is available on the socket. This call is documented in POE::Kernel as follows:

# Watch for read readiness on a filehandle. $kernel->select_read( $file_handle, $event, @optional_args );
I would like to use the optional arguments to communicate with my event handler. To do this, I created the following line in my event handler:
($k, $sock, $optarg1) = @_[KERNEL, ARG0, ARG1];
I was expecting $optarg1 to be the first optional argument that I set in the select_read call. Instead, it always seemed to be set to zero. I searched a bunch, but didn't find anything, then asked in the CB for some help. I had to run before anyone had time to help me out, so I thought I'd post the question here.

While getting my references setup for this article, I stumbled across the solution in POE::Kernel:

Select events include two parameters. ARG0 holds the handle of the file that is ready. ARG1 contains 0, 1, or 2 to indicate whether the filehandle is ready f +or reading, writing, or out-of-band reading (otherwise knows as "expe +dited" or "exception"). ARG2..$#_ contain optional additional parameters passed to POE::Kernel +'s various I/O watcher methods.
D'oh! As you can see, my problem is solved by the following:
($k, $sock, $status, $optarg1) = @_[KERNEL, ARG0, ARG1, ARG2];
Thanks to all who tried to help out in CB. I hope this helps others who walk down the same path I did.

-Craig


In reply to Accessing POE select_read optinal_args - Solved by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.