in reply to Re^13: Help editing a file based off seach criteria
in thread Help editing a file based off seach criteria

This is an example... The match im trying to make is a commented filed in a file that has the pattern END in the string. So create a file with junk in it, put some commented field in the file #END. From here I need to be able to jump up one line, insert data, then place a new line under the new data. Some compaines restrict mod installs, as on platforms like aix, upgrades will sometimes render the mod usless, which is this case, so using CPAN is not an option. Even looking at TIE im not seeing an easy option for this.
open DATA, "</home/file.conf"; while (<DATA>) { if(m/\END\b/) { print "$.\n"; print "$_\n"; $pos = $.; $pos--; chomp $pos; $DESIRED_LINE_NUMBER = $pos; } } #$. = 0; do { $LINE = <DATA> } until $. == $DESIRED_LINE_NUMBER || eof; print $LINE;
Result: 1675 ---> Line found matching Search # *** END NEW MAPPING RULES SECTION *** ---Txt from Line -->Blank Line where I need to add values.

Replies are listed 'Best First'.
Re^15: Help editing a file based off seach criteria
by Corion (Patriarch) on Jan 13, 2009 at 18:45 UTC

    Thank you for your advice for how to replicate your code. As you might have noticed, I already modified your program in my reply to actually include a data portion in the __DATA__ section. I still don't see how your program would work, but if it works for you, then just use what works for you.

    You might want to re-read Yes, even you can use CPAN, as it shows how to keep a private installation of modules, which will not break if other components of the system get upgraded. Or you could pursue the approach of copying the code from Tie::File into your program. But you seem to have far more experience in that area than I do, so I will leave the best approach to your judgement.