sliles has asked for the wisdom of the Perl Monks concerning the following question:
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;}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern matching
by dmmiller2k (Chaplain) on Jan 10, 2002 at 02:47 UTC | |
|
Re: pattern matching
by mkmcconn (Chaplain) on Jan 10, 2002 at 03:03 UTC | |
|
Re: pattern matching
by Zaxo (Archbishop) on Jan 10, 2002 at 03:01 UTC | |
|
Re: pattern matching
by boo_radley (Parson) on Jan 10, 2002 at 04:02 UTC | |
|
Re: pattern matching
by Rich36 (Chaplain) on Jan 10, 2002 at 03:26 UTC | |
|
Re: pattern matching
by particle (Vicar) on Jan 10, 2002 at 03:52 UTC |