theravadamonk has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print a file from Bottom to Top (reverse order)
by haukex (Archbishop) on Jun 20, 2018 at 16:59 UTC | |
|
Re: print a file from Bottom to Top (reverse order)
by thanos1983 (Parson) on Jun 20, 2018 at 16:33 UTC | |
|
Re: print a file from Bottom to Top (reverse order)
by Laurent_R (Canon) on Jun 20, 2018 at 17:59 UTC | |
by theravadamonk (Scribe) on Jun 20, 2018 at 18:29 UTC | |
by Laurent_R (Canon) on Jun 20, 2018 at 18:45 UTC | |
by theravadamonk (Scribe) on Jun 22, 2018 at 15:45 UTC | |
by AnomalousMonk (Archbishop) on Jun 20, 2018 at 19:04 UTC | |
|
Re: print a file from Bottom to Top (reverse order)
by afoken (Chancellor) on Jun 20, 2018 at 18:49 UTC |