I am trying to write a basic Perl script to do some string manipulation. I get the "Existing_Value_To_Be_Changed" and the "New_Value" as user inputs.
The file has multiple block of lines such as the following -
foo_bar_xyz000123 := abcd (100010
01010111111001011010001010); - (Not in same line as previous)
The foo_bar_abc
part of the string appears multiple times in the file. The only numbers following it uniquifies each appearance.
When I traverse line by line in Perl, how do I replace all the 0
's(Existing_Value_To_Be_Changed) with 1
's(New_Value) after the foo_bar_xyz
has been matched (in all occurrences). But I need to start after the (
and keep going on to the following line(s) until the );
is encountered and stop after that.
Edit
I already completed the part about navigating my way into those specific blocks of lines. I am stuck in the character search & replacing part.
$var = 'false';
while <File> {
if (pattern matches) {
$var = 'true';
}
if ($var eq "true") {
push(@array, $_);
if ( $_ contains ");" ) {
$var = 'false';
}
}
}
When the current line is stored in a variable, what is the best way to do the replace after the (
only until );
part?
Edit
The Existing_Value_To_Be_Changed and New_Value are user inputs, and if one is 0, then the other is 1 and vice versa as it is a binary string that contains only 0s and 1s.