I want to go with while loop.Why? Given what you're doing in your second code sample, you could do it as well on the items of the @file array in your first code sample.
For example:
Or, simplifying a bit the syntax:open(FILE, "<myfile.txt"); @file = reverse <FILE>; foreach (@file) { chomp; # --> Note: no need to chomp, i +t just forces you to add the \n again when you print next unless /\S/; # skip blank lines --> Note: this is useless giv +en that you print only line matching the /Passed CLEAN/ pattern if (/Passed CLEAN/) { #search string Passed CLEAN print "$_ \n"; # print ALL lines containing Passed CLEAN } }
That should work fine unless your file is truly huge and won't fit into memory. If your file is too big, then the File::ReadBackwards is the only simple solution;open(FILE, "<myfile.txt"); @file = reverse <FILE>; foreach (@file) { print if /Passed CLEAN/; }
In reply to Re: print a file from Bottom to Top (reverse order)
by Laurent_R
in thread print a file from Bottom to Top (reverse order)
by theravadamonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |