Reading file backward in perl? (Slightly OT)
Hello SuSE folkz, Could somebody please advise me how to read file in perl but backward from the bottom to the top. Conventional loop open (FH "file.txt"); while ($line = <FH>) { print $line."\n"; } doesn't work in this case. Thanks. Alex
On Thursday 13 March 2003 14:28, Alex Daniloff wrote:
Hello SuSE folkz, Could somebody please advise me how to read file in perl but backward from the bottom to the top.
Something like: perl -ne '@data=<>; print reverse @data;' < data.txt should get you started. -- "...our desktop is falling behind stability-wise and feature wise to KDE ...when I went to Mexico in December to the facility where we launched gnome, they had all switched to KDE3." - Miguel de Icaza, March 2003
#!/usr/bin/perl -w my @rev = <> ; while (@rev) { print pop(@rev) ; } On Thursday 13 March 2003 01:28, Alex Daniloff wrote:
Hello SuSE folkz, Could somebody please advise me how to read file in perl but backward from the bottom to the top.
Conventional loop
open (FH "file.txt"); while ($line = <FH>) {
print $line."\n";
}
doesn't work in this case.
Thanks. Alex
Or the smart ass response: tac foo | perl -ne "print $_;" -- -ckm
participants (4)
-
Alex Daniloff
-
Christopher Mahmood
-
Derek Fountain
-
Paul Alfille