in reply to Re: Filehandles and Input and Output Filters
in thread Filehandles and Input and Output Filters
Thanks again for "__DATA__" as well. There is one thing I would like mention: I used to write FH instead of $FH in open() as the file-handler. But both of them work. I did not know it. Please have a look at this:#!/usr/bin/perl -w open ($FH,'| sort -n') or die($!); while(<ARGV>){ print $FH $_; } close $FH;
The line numbers are being printed out first and then the sorted list of the words. That means (this is what I understand now) that the data are being fed to the "sort" command which returns its result when all the input to it is fed.[demo@localhost Perl]$ cat bar.pl #!/usr/bin/perl -w open (FH,'| sort') or die($!); $count=0; while(<ARGV>){ print FH $_; print $count++ . "\n"; } close FH; [demo@localhost Perl]$ bar.pl words 0 1 2 3 4 A ABC a to z Buy Why
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Filehandles and Input and Output Filters
by roboticus (Chancellor) on Nov 04, 2011 at 00:51 UTC |