You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Goehring, Chuck Mr., RCI - San Diego" <cg...@resourceconsultants.com> on 2003/04/08 01:30:23 UTC

[mp2] File I/O

mp2 Guys,

The test program below works fine under mp1.  Under mp2, no error is thrown but nothing is written to the file.  I built mod_perl-1.99_08.


Thanks
Chuck

####################################################
$| = 1;
use CGI;
use strict;
my $cgiOBJ = new CGI;
print $cgiOBJ->header(-expires=>'-1d'),
      $cgiOBJ->start_html(-TITLE=>'testenv2.cgi',
                          -BGCOLOR=>'#FFFFFF');

# Just some output to the web page.
print "<BR>PATH: " . $ENV{"PATH"};

  # Fil i/o
    use IO;
    my $log2 = 'xxLOG_FILE.TXT'; 
    print "<br>dbappobj.pm._LogEntry.log2=" . $log2;
    my $fh2 = new IO::File(">> $log2");
    if($fh2) {  # Print to browser.
        print '<br>fh2 is GOOD';
    } else {
        print '<br>fh2 is BAD';
    }
    # Print to file.
    eval{  
       print $fh2 'This is a test print';
    }; 
    print '<br>error= ' . $@;
   
    $fh2->close();
    # Print to browser.
    print '<br>After file write.';

print $cgiOBJ->end_html;

Re: [mp2] File I/O

Posted by Stas Bekman <st...@stason.org>.
Goehring, Chuck Mr., RCI - San Diego wrote:
> mp2 Guys,
> 
> The test program below works fine under mp1.  Under mp2, no error is thrown but nothing is written to the file.  I built mod_perl-1.99_08.

You must be using 'SetHandler modperl' instead of 'SetHandler perl-script', 
the former requires you to use $r->print instead of print. See:
http://perl.apache.org/docs/2.0/user/config/config.html#C_SetHandler_

> # Just some output to the web page.
> print "<BR>PATH: " . $ENV{"PATH"};

I'm not sure if it's going to be easy to try to detect this and complain when. 
I suppose we could override print and check that the selected stream is a tied 
STDOUT, but I'm afraid it'll create too much of an overhead to do that on 
every call.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com