mani
mani

Reputation: 11

perl script to match comma

I have a netlist generated from schematic. This netlist includes power pins. Iam trying to write a perl script to remove power pins from netlist. As part of this i have to search for a string that matches the pattern shown below:

", );" 

I have used the following code and it is not working

$line =~ s/,\s+\);//g 

I have observed that pattern end with comma are matched but pattern starting with comma or pattern with comma in middle are not matched. Any suggestions on how to get this work

Upvotes: 1

Views: 2863

Answers (2)

mani
mani

Reputation: 11

Thank you every one. I have found the problem. The problem was that the pattern to be recognized is split in to two different lines. The "," is in one line followed by ");" in next line. At first, iam removing the new line character and assumed that the next line will get appended to the current line, which is not happening. Hence, the pattern matching did not work.

To resolve this, i have to read the file once again and then replace the pattern.

Upvotes: 0

Jeff Holt
Jeff Holt

Reputation: 3190

You need to use this instead:

s/,\s*\);//

You should be defensive and be able to handle no whitespace between the , and the ). You have to escape the ). See perldoc perlre for more info.

Upvotes: 1

Related Questions