I'm having trouble repleacing a set of strings in a file with something else. I already checked on stackoverflow and on other sites but something is missing. I have a file that contains the following:
12 [ fillcolor="#62cb62", fontcolor="#ffffff", label="HealthStatus 12", shape=hexagon ]
520 [ fillcolor="#ffc0cb", fontcolor="#000000", label="A-SYNT 520", shape=parallelogram ]
521 [ fillcolor="#ffc0cb", fontcolor="#000000", label="A-CONF 521", shape=parallelogram ]
522 [ fillcolor="#ffc0cb", fontcolor="#000000", label="A-SAFE 522", shape=parallelogram ]
12 -> 522 [ color="#000000" ]
12 -> 521 [ color="#000000" ]
12 -> 520 [ color="#000000" ]
I want to replace
12 [ with 12 HealthStatus [
520 [ with 520 A-SYNT [
521 [ with 521 A-CONF [
522 [ with 522 A-SAFE [
12 -> with 12 HealthStatus ->
I already have in an array the numbers and the strings and I save them in the variables $proxyid and $proxyname .
Here's the code I'm using
rename($GVFILE, $GVFILE.'.bak');
open(OUT, '>'.$GVFILE) or die $!;
print_log ($IL, "## proxystack $#proxy_stack");
open(IN, '<'.$GVFILE.'.bak') or die $!;
for (my $cursor = 0; $cursor <= $#proxy_stack; $cursor++) {
$proxy_length = 0;
$proxyid = $proxy_stack[$cursor];
$proxyname = $proxy_stack[$cursor]{'name'};
print_log ($IL, "## debug $proxyid $proxyname");
print_log ($IL, "## debug cursor $cursor");
while(<IN>)
{
$_ =~ s/$proxyid \[/$proxyid $proxyname \[/g;
$_ =~ s/$proxyid -\>/$proxyid $proxyname -\>/g;
print OUT $_;
}
}
close(IN);
close(OUT);
I'm sure I have everything in $proxy_stack since I'm printing it and I get all the elements I expect but only the first replacement is performed.