polr has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: need help editing lines of a file
by davorg (Chancellor) on Dec 18, 2001 at 19:39 UTC

    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.

Re: need help editing lines of a file
by dragonchild (Archbishop) on Dec 18, 2001 at 19:43 UTC
    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.