On Mon, May 16, 2005 at 03:06:51PM +0400, Laura wrote:
> Hi, please sorry, i`m newbie in POE and have a lot of
> problems...
>
> Why doesn`t variables of HEAP changed?
> There is a little chunk of program(2 subs):
>
> sub one {
>
> $_[HEAP]->{VARIABLE}=0;
> for(1..4)
> {
> $_[KERNEL]->yield("two");
> }
> print "VARIABLE: ",$_[HEAP]->{VARIABLE};
>
> }
>
> sub two {
> $_[HEAP]->{VARIABLE}++;
> }
>
> It will print "VARIABLE: 0", but why? I`ve updated it in
> 'two', it must be 1(cause of ++).
Er, no. "yield" means "put this event in the queue to be run", so your
"two" events aren't going to get called until after the "one" event
exits.
Replace the print with
$_[KERNEL]->yield("three");
and add
sub three {
print "VARIABLE: ",$_[HEAP]->{VARIABLE};
}
and I think you'll see the result you expect.
--
Matt S Trout Website: http://www.shadowcatsystems.co.uk
Technical Director E-mail: mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.