Reading from a pipe in Perl April 25, 2007
Posted by suniljagadish in Perl.trackback
Many a times I have come across scenarios where I have to read from a pipe in my Perl script. It is scenarios where I zcat from a file into my program -
$ zcat myfile.gz | ./myscript.pl > dump.txt
This can be done pretty easily:
while(<>) {
# $_ is a special variable that stores the current line read
# Here, my field seperator is ^A
@fields = split(/001/,$_);$_ = <>; # Read the next line, for whatever reason
if($_) {
print $_;
}# Do anything else here
}
Comments»
No comments yet — be the first.