perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Foertsch <torsten.foert...@gmx.net>
Subject Re: Sth I don't understand about pnotes
Date Fri, 16 Sep 2005 10:33:12 GMT
On Friday 16 September 2005 12:08, Anthony Gardner wrote:
> Can s.o. explain what is wrong with the following code
> ....
>
> $r->pnotes('KEY' => push( @{ $ar }, $some_val ) );
>
> because, when it comes to getting the value from
> pnotes later with .... $r->pnotes(KEY), it returns the
> number of elements in the array and not the array ref.
>
> I've had to write ......
>
> my $ar = $r->pnotes('KEY') || [];
> push( @{ $ar }, $debug_str );
> $r->pnotes( 'KEY' => $ar );

Quoteing perldoc -f push:

       push ARRAY,LIST
               Treats ARRAY as a stack, and pushes the values of LIST onto the
               end of ARRAY.  The length of ARRAY increases by the length of
               LIST.  Has the same effect as

                   for $value (LIST) {
                       $ARRAY[++$#ARRAY] = $value;
                   }

               but is more efficient.  Returns the new number of elements in
               the array.

push returns the new number of elements. This is what you see.

Torsten

Mime
View raw message