"Global" here doesn't relate to Perl's concept of package or file-scope variables. It just relates to non-local scoping.

You have a process that in a standalone, linear program might be a simple subroutine that uses a few local variables--but it takes several seconds to run. Say:

sub getFromDB { my $dbh = shift; my $sth = $dbh->prepare( 'SELECT (...) from ... left inner join ... union ... where ... + in ( select ... )' )or die $dbi->errstr; return sth->fetchall_arrayref; }

But that takes say 5 seconds to run.

With POE, you now have to break that up so that each part of the processing takes less than say 1/10th of a second, so that your program remains responsive to the sockets it is monitoring. That means breaking that 3 line sub into 50 pieces. Where do you start?

And you have to arrange for those 50 pieces to run in sequence. How?

And the local variables that Perl will clean up automatically, now have to persist across the callbacks. But what happens if something goes wrong part way through? You also have to add code to clean up afterwards.

With threads, that subroutine stays as is--simple. And the main thread stays responsive to the sockets.

And if something goes wrong in the thread, you just terminate it and spawn a new one. Clean up is automatic.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^4: Why are people not using POE? by BrowserUk
in thread Why are people not using POE? by johnnywang

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.