sunshine_august has asked for the wisdom of the Perl Monks concerning the following question:

hi, all monks:

I am learning POE, and I am confused about POE::Session's parameter HEAP.

I notice that POE::Session use its parameter HEAP like a hash, but I think HEAP should be a reference, and it is documented: " Heaps are by default anonymous hash references":

The example from its document:
sub _start_handler { $_[HEAP]{ts_start} = time(); }
why does it use
$_[HEAP]{ts_start} = time();
rather than
$_[HEAP]->{ts_start} = time();

I think the $_[HEAP] should be a reference, it can't not be use like $_[HEAP]{ts_start}, but in POE::Session, it did use like this way and it did work well.

Can anyone give a tip?

Replies are listed 'Best First'.
Re: How can POE use a hash reference like a hash?
by rcaputo (Chaplain) on Dec 11, 2008 at 06:05 UTC

        That node seems to agree with me: Arrows are optional between two subscripts.

        In $x->[0]->[1], $x is not a subscript but both [0] and [1] are. We may remove the second arrow without changing the expression, giving $x->[0][1]. The arrow between $x and [0] isn't between two subscripts, however, so it is required to maintain equivalence with the original expression.