N
naruto canada
hi
I've encountered this code some times ago:
#!/usr/bin/env perl
$i=1;
while (<>) {
if (($len = length($_)) > $lmax) {
$lmax = $len;
@longest =($i.":$_");
}
elsif ($len == $lmax) {
push(@longest, $i.":$_");
}
$i=$i+1;
}
print @longest;
This code print longest lines from stdin. Strangely, it works without
cat. If my understanding is correct, "<>" (stdin) should require "cat"
to work. Can someone explain it?
Right now, for example, it works both ways like:
cat 1.txt | longest.line.pl
longest.line.pl 1.txt
I've encountered this code some times ago:
#!/usr/bin/env perl
$i=1;
while (<>) {
if (($len = length($_)) > $lmax) {
$lmax = $len;
@longest =($i.":$_");
}
elsif ($len == $lmax) {
push(@longest, $i.":$_");
}
$i=$i+1;
}
print @longest;
This code print longest lines from stdin. Strangely, it works without
cat. If my understanding is correct, "<>" (stdin) should require "cat"
to work. Can someone explain it?
Right now, for example, it works both ways like:
cat 1.txt | longest.line.pl
longest.line.pl 1.txt