Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Re: Net::AIM with another script?

by hoopsbwc34 (Initiate)
on Aug 18, 2003 at 00:04 UTC ( [id://284460]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Net::AIM with another script?
in thread Net::AIM with another script?

Any chance you can point me to URL for a good example script? I'm not really sure where to start... there seem to be a lot of uses and applications of POE from looking at poe.perl.com
  • Comment on Re: Re: Re: Re: Net::AIM with another script?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Net::AIM with another script?
by kelan (Deacon) on Aug 18, 2003 at 14:14 UTC

    I haven't read it (I plan to), but there was recently An introduction to POE posted to the monastery. You may want to start there.

    kelan


    Perl6 Grammar Student

Re: Re: Re: Re: Re: Net::AIM with another script?
by eric256 (Parson) on Aug 18, 2003 at 14:07 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found