What was wrong with the answers
that you got the last time you asked this
question?
Oh, and learn to choose better subject
lines.
Originally posted as a Categorized Answer.
| [reply] |
If I understand you correctly, you want
- Step through a text file line by line
- If you come across a line with a certain set of characteristics ...
- Then you want to do something to the line just prior
You have a number of options. The easiest to implement is to read the file into an array, then manipulate it. Something like this:
my @lines = <>;
foreach my $index (0 .. $#lines) {
if ($lines[$index] =~ /word/) {
# Do what you want here, but to $lines[$index - 1]
}
}
The only problem with that method is if your text file is over 50% of your available RAM. Then, instead of being blazingly fast, it's only moderately fast.
Originally posted as a Categorized Answer. | [reply] [d/l] |