File I want to parse:
input Pattern;
input SDF;
input ABC
input Pattern;
output Pattern;
output XYZ;
In perl, usual operation is scan line by line.
I want to check that if
current line has output Pattern; and previous line (or all previous lines)has input Pattern;
then change all the previous lines matches to "input Pattern 2;" and current line to "output Pattern2;".
It is complicated ,I hope I have explained properly.
Is it possible in Perl to scan and change previous lines after they have been read?
Thanks
If this is your data:
then, the following snippet will read the whole file and change text accordingly:
Then, you may close your file and check the string:
=>
You may even include a counter
$nwhich will be incremented after each successful match (by code assertion(?{ ... }):The substitution will now start with
input Pattern 2;und increment subsequently.