Practical mod_perl / HTML Book /



previous page: 6.4.5. Redirecting STDOUT into a Scalar Variable
  
page up: HTML Version of the book
  
next page: 6.4.7. Formats

6.4.6. print( )


Under mod_perl, CORE::print( ) (using either STDOUT as a filehandle argument or no filehandle at all) will redirect output to Apache::print( ), since the STDOUT file handle is tied to Apache. That is, these two are functionally equivalent:

print "Hello";
$r->print("Hello");

Apache::print( ) will return immediately without printing anything if $r->connection->aborted returns true. This happens if the connection has been aborted by the client (e.g., by pressing the Stop button).

There is also an optimization built into Apache::print( ): if any of the arguments to this function are scalar references to strings, they are automatically dereferenced. This avoids needless copying of large strings when passing them to subroutines. For example, the following code will print the actual value of $long_string:

my $long_string = "A" x 10000000;
$r->print(\$long_string);

To print the reference value itself, use a double reference:

$r->print(\\$long_string);

When Apache::print( )sees that the passed value is a reference, it dereferences it once and prints the real reference value:

SCALAR(0x8576e0c)

 

Continue to:

  • prev: 6.4.5. Redirecting STDOUT into a Scalar Variable
  • Table of Contents
  • next: 6.4.7. Formats







TOP
previous page: 6.4.5. Redirecting STDOUT into a Scalar Variable
  
page up: HTML Version of the book
  
next page: 6.4.7. Formats


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com