Hi, Monks, I want to know how to print a file from Bottom to Top (reverse order).
I found this below link with below code
https://www.perlmonks.org/?node_id=361397
open(FILE, "<myfile.txt"); @file = reverse <FILE>; foreach (@file) { #process line }
Given below is My CODE with while loop, I want to go with while loop. How can I print from Bottom to Top ?
How can I insert reverse order in to while loop?
What's the easiest way ? I DO hope U monks will come with ideas...
#!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use CGI::Carp 'fatalsToBrowser'; # use only for testing #my $date = localtime(); $ENV{"PATH"} = "/usr/sbin:/usr/bin:/sbin:/bin"; open FILE, '<', '/var/log/maillog' or die $!; while (<FILE>){ chomp; next unless /\S/; # skip blank lines if (/Passed CLEAN/) { #search string Passed CLEAN print "$_ \n"; # print ALL lines containing Passed CLEAN } } close FILE;
In reply to print a file from Bottom to Top (reverse order) by theravadamonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |