The POE site does seem a little complex. Here is an example of a script that calls one function once, then that function starts a loop of calls to a second function.

use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start + is automagicaly the first event continue => \&looping #user defin +ed event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting in 5!\n"; $kernel->delay( continue => 5 ); # call the continue event in fi +ve seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "$heap->{counter} iteration!\n"; if ($heap->{counter} < 10) { $kernel->delay( continue => 1 ); #start state continue in 1 +seconds } }

Now that might look confusing but try it out. Its actualy very nice, and fun. Beats the crap out of making a loop and having counter variables to see if its time to run it or not.

Now here is the same code, but i cut and pasted parts and changed the intervals. This is why poe is pretty!

use strict; use POE; use POE::Session; POE::Session->create( inline_states => { _start => \&start, #_start + is automagicaly the first event continue => \&looping #user defin +ed event we will call later } ); POE::Session->create( inline_states => { _start => \&start2, #_star +t is automagicaly the first event continue => \&looping2 #user defi +ned event we will call later } ); $poe_kernel->run(); sub start { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting A in 5! (Loops every .5 seconds) \n"; $kernel->delay( continue => 5 ); # call the continue event in fi +ve seconds } sub looping { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "A: $heap->{counter} iteration! \n"; if ($heap->{counter} < 100) { $kernel->delay( continue => .5 ); #start state continue in 1 + seconds } } sub start2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; print "Starting B in 7 (Loops every 2 seconds)!\n"; $kernel->delay( continue => 7 ); # call the continue event in fi +ve seconds } sub looping2 { my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION]; $heap->{counter}++; #the heap is just a hash we can put goodi +es in. print "B: Iteration number $heap->{counter}!\n"; if ($heap->{counter} < 100) { $kernel->delay( continue => 2 ); #start state continue in 1 +seconds } }

Tested and pre-approved. :-)

___________
Eric Hodges

In reply to Re: Re: Re: Re: Re: Net::AIM with another script? by eric256
in thread Net::AIM with another script? by hoopsbwc34

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.