Why doesn't the following code snippet work? What I want to do is this: Anytime there is an opening and closing curly brace after an "if" followed by an "else", delete both of these curly braces:if (/BEGIN PATTERN/ ... /END PATTERN/)
---------------------- Apparently it is not meeting the condition of the "if' statement, because nothing is changed in my text. This seems like it should work. Any ideas? Thanks for all the suggestions... you folks are great! SusanCode Snippet: # Beginning pattern: 'if' followed by 0 or more characters #followed by the nearest { brace # # Ending pattern: 0 or more chars. followed by nearest # } brace followed by an 'else' if ( /if.*?{/ .. /.*?}.*?else/ ) { $_ =~ s/{//; $_ =~ s/}//; } ----------------------------------------------------- Here is the text I am reading: if (c=e) { // delete this curly brace call pgme; call pgmd; } // delete this curly brace else {call pgmd; // keep these curly braces call pgmc;} I want the text to be changed to the following: if (c=e) call pgme; call pgmd; else {call pgmd; call pgmc;}
In reply to pattern matching by sliles
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |