J
John Kelly
#!/usr/bin/perl
use strict;
use warnings;
my $data;
while (<>) {
chomp;
if (!$data && $_) {
$data = $_;
}
}
print "data=$data\n";
This code reads STDIN and remembers the first non-empty line. That's
all it cares about.
But it also keeps reading till EOF, acting like the "cat" utility, to
flush the extra input and avoid broken pipe errors.
But reading line by line, just to throw away the unwanted garbage, is
inefficient. I would like to jump out of the loop and "bulk flush" the
remaining input stream.
I don't think
will work, because that it flushes the buffer, not the entire input
stream. I want to flush the whole file. And keep in mind, I don't want
a broken pipe either.
Suggestions?
use strict;
use warnings;
my $data;
while (<>) {
chomp;
if (!$data && $_) {
$data = $_;
}
}
print "data=$data\n";
This code reads STDIN and remembers the first non-empty line. That's
all it cares about.
But it also keeps reading till EOF, acting like the "cat" utility, to
flush the extra input and avoid broken pipe errors.
But reading line by line, just to throw away the unwanted garbage, is
inefficient. I would like to jump out of the loop and "bulk flush" the
remaining input stream.
I don't think
$io->flush
flush causes perl to flush any buffered data at the perlio
api level. Any unread data in the buffer will be discarded,
will work, because that it flushes the buffer, not the entire input
stream. I want to flush the whole file. And keep in mind, I don't want
a broken pipe either.
Suggestions?