"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.
In reply to Re^4: Why are people not using POE?
by BrowserUk
in thread Why are people not using POE?
by johnnywang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |