Files and Safe IO
Read from Text
Safe IO code often starts by treating input as text that must be read one line at a time.
Read from Text
scalar_read.pl
use strict;
use warnings;
my $first = ;
my $content = "$first\nbeta\n";
my $line = "";
if ($content =~ /^([^\n]*)/) {
$line = $1;
}
print "first=$first\n";
print "line=$line\n";
use strict;
use warnings;
my $first = ;
my $content = "$first\nbeta\n";
my $line = "";
if ($content =~ /^([^\n]*)/) {
$line = $1;
}
print "first=$first\n";
print "line=$line\n";
use strict;
use warnings;
my $first = ;
my $content = "$first\nbeta\n";
my $line = "";
if ($content =~ /^([^\n]*)/) {
$line = $1;
}
print "first=$first\n";
print "line=$line\n";
input text
Input text is data the program reads before it decides what to do next.