books
Free Books / Computers / Practical mod_perl /

previous page: 6.4.5. Redirecting STDOUT into a Scalar Variable
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 6.4.7. Formats

6.4.6. print( )




Description

This section is from the "Practical mod_perl" book, by Stas Bekman and Eric Cholet. Also available from Amazon: Practical mod_perl

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

Books by Stas Bekman:















TOP
previous page: 6.4.5. Redirecting STDOUT into a Scalar Variable
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: 6.4.7. Formats

Topics

  • Animals
  • Architecture
  • Arts
  • Business
  • Computers
  • Crafts
  • Fairy Tales
  • Finance
  • Flora and Plants
  • Cooking
  • Gardening
  • Health and Healing
  • History
  • Home Improvements
  • Languages
  • New Age
  • Novels
  • Real Estate
  • Reference
  • Religion
  • Science
  • Society
  • Sports
  • Travel
  • Outdoors


Search

My Books

Headaches Begone! A Systemic Approach To Healing Your Headaches
Don't Let Your Bike Seat Ruin Your Sex Life Book

Discover

  • Answers FAQ

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

© 2007-2021 StasoSphere.com