Files and Safe IO
Build Output Text
Before writing data, a program can build the exact output text it intends to store.
Build Output Text
scalar_write.pl
use strict;
use warnings;
my $word = ;
my $buffer = "";
$buffer = $buffer . "status=$word\n";
chomp $buffer;
print "word=$word\n";
print "buffer=$buffer\n";
use strict;
use warnings;
my $word = ;
my $buffer = "";
$buffer = $buffer . "status=$word\n";
chomp $buffer;
print "word=$word\n";
print "buffer=$buffer\n";
use strict;
use warnings;
my $word = ;
my $buffer = "";
$buffer = $buffer . "status=$word\n";
chomp $buffer;
print "word=$word\n";
print "buffer=$buffer\n";
output buffer
An output buffer is a string that collects text before it is written somewhere.