質問

I have the following PHP code which opens the output buffer, includes a file, stores it in a variable, and clears the buffer:

ob_start(); 
include('test.html');
$input=ob_get_clean(); 

How would the equivalent look in Perl?

役に立ちましたか?

解決 2

The special variable $| . When set to nonzero, does a buffer flush after every write or print

他のヒント

$| = 1; will turn on disable buffering for the currently selected handle (STDOUT by default). In other words,

$| = 1;

is functionally equivalent to

use IO::Handle qw( );   # Not needed since 5.14.
select()->autoflush(1);

which usually means

use IO::Handle qw( );   # Not needed since 5.14.
STDOUT->autoflush(1);

So the equivalent would be:

# open a file handle try to get test.html
open(my $fh, "<", "test.html") ||
   die 'Could not open test.html: '.$!;
# return the currently selected filehandle
select($fh);
#clear the output buffer
select()->autoflush(1);

References

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top