You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Anthony Gardner <cy...@yahoo.co.uk> on 2005/09/16 12:08:25 UTC
Sth I don't understand about pnotes
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 );
Apache/1.3.33, mod_perl/1.29
CIA
-Anthony
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
Re: Sth I don't understand about pnotes
Posted by Anthony Gardner <cy...@yahoo.co.uk>.
Yeah, thta's cheeky. I totally overlooked what push
was returning.
I'll remember for next time.
Cheers all.
--- Damyan Ivanov <di...@creditreform.bg> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> 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.
>
> push returns the number of array's elements. And
> this gets stored in the
> 'KEY' of pnotes. Nothing wrong here.
>
>
> > I've had to write ......
> >
> > my $ar = $r->pnotes('KEY') || [];
> > push( @{ $ar }, $debug_str );
> > $r->pnotes( 'KEY' => $ar );
>
>
http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_pnotes_
> $old_val = $r->pnotes($key => $val);
> $val = $r->pnotes($key);
> $hash_ref = $r->pnotes();
>
> So
> push @{ $r->pnotes()->{'KEY'} }
> should do what you want.
>
> The abofe doc is for mod_perl2, but as far as I see,
> the same applies
> for mod_perl 1 as well.
>
>
>
> dam
> - --
> Damyan Ivanov 0x9725F63B
> Creditreform Bulgaria
> divanov@creditreform.bg
> http://www.creditreform.bg/
> phone: +359(2)928-2611, 929-3993 fax:
> +359(2)920-0994
> mob. +359(88)856-6067 ICQ 3028500
> dam@jabber.minus273.org/Gaim
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird -
> http://enigmail.mozdev.org
>
>
iD8DBQFDKqBlHqjlqpcl9jsRAtFaAJ4zrkS2BCirN8s5jQYWjOGVi4o0SwCgnT/l
> rtNpyRgQIYpZdP3T97Bo5u8=
> =rvA/
> -----END PGP SIGNATURE-----
>
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
Re: Sth I don't understand about pnotes
Posted by Damyan Ivanov <di...@creditreform.bg>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
push returns the number of array's elements. And this gets stored in the
'KEY' of pnotes. Nothing wrong here.
> I've had to write ......
>
> my $ar = $r->pnotes('KEY') || [];
> push( @{ $ar }, $debug_str );
> $r->pnotes( 'KEY' => $ar );
http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_pnotes_
$old_val = $r->pnotes($key => $val);
$val = $r->pnotes($key);
$hash_ref = $r->pnotes();
So
push @{ $r->pnotes()->{'KEY'} }
should do what you want.
The abofe doc is for mod_perl2, but as far as I see, the same applies
for mod_perl 1 as well.
dam
- --
Damyan Ivanov 0x9725F63B Creditreform Bulgaria
divanov@creditreform.bg http://www.creditreform.bg/
phone: +359(2)928-2611, 929-3993 fax: +359(2)920-0994
mob. +359(88)856-6067 ICQ 3028500 dam@jabber.minus273.org/Gaim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDKqBlHqjlqpcl9jsRAtFaAJ4zrkS2BCirN8s5jQYWjOGVi4o0SwCgnT/l
rtNpyRgQIYpZdP3T97Bo5u8=
=rvA/
-----END PGP SIGNATURE-----
Re: Sth I don't understand about pnotes
Posted by Carl Johnstone <mo...@fadetoblack.demon.co.uk>.
From: "Anthony Gardner" <cy...@yahoo.co.uk>
> Can s.o. explain what is wrong with the following code
> ....
>
> $r->pnotes('KEY' => push( @{ $ar }, $some_val ) );
>
It's a perl problem - not a mod_perl problem. push returns the new number of
elements on the array. So in effect you're doing:
$r->pnotes('KEY' => number_of_elements_in_array );
Your other snippit looks OK to me.
Carl
Re: Sth I don't understand about pnotes
Posted by Torsten Foertsch <to...@gmx.net>.
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