in reply to Perl: How to match a line and print words at line immediately above it?
This is a quick example and presumes you are not going to find a match on the first line of the file.my $previous = ''; foreach my $line (@arrayfile) { if ($line =~ m/WhateverIWantToMatch/) { print "$previous\n" if ($previous); } $previous = $line; #### This line now becomes the previous line for + the next array element seeing as ALL lines in the file will be proce +ssed }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl: How to match a line and print words at line immediately above it?
by locked_user sundialsvc4 (Abbot) on Nov 01, 2013 at 14:59 UTC |