On Wed, 3 May 2000, Doug MacEachern wrote: > On Wed, 3 May 2000, Jeffrey W. Baker wrote: > > > Apache::print() dereferences its arguments. For example, this code: > > > > my $foo = "bar"; > > $r->print(\$foo); > > > > prints "bar" instead of the expected SCALAR(0xDEADBEEF). Can anyone > > explain the purpose of this behavior, or is it a misfeature? In my case, > > this is not the desired behavior. > > it only pulls that stunt for strings. assuming you're only printing the > reference for debugging purposes, just stringify it first: > > my $foo = \"bar"; > > print "$foo"; > > or, geoff's trick: > > my $foo = "bar"; > > print \$foo . ""; > > do you need to avoid this feature for something other than debugging? Not strictly for debugging, but for introspection. I was toying with a module that pokes around inside the perlguts of a running mod_perl server and makes some nice displays out of them. Nothing for production/money mind you, just amusement. Here is a patch I made against the documentation in Apache.pm. Actually, I had to attach it because it was wrapping. Regards, Jeffrey
--- Apache.pm.orig Thu May 4 08:20:59 2000 +++ Apache.pm Thu May 4 08:31:31 2000 @@ -911,7 +911,21 @@ =item $r->print( @list ) This method sends data to the client with C<$r-E<gt>write_client>, but first -sets a timeout before sending with C<$r-E<gt>hard_timeout>. +sets a timeout before sending with C<$r-E<gt>hard_timeout>. This method is +called instead of CORE::print when you use print() in your mod_perl programs. + +This method treats scalar references specially. If an item in @list is a +scalar reference, it will be dereferenced before printing. This is a +performance optimization which prevents unneeded copying of large strings, +and it is subtly different from Perl's standard print() behavior. + +Example: + +$foo = \"bar"; print($foo); + +The result is "bar", not the "SCALAR(0xDEADBEEF)" you might have expected. If +you really want the reference to be printed out, force it into a scalar +context by using print(scalar($foo)). =item $r->send_fd( $filehandle )