I am doing patern matching by extracting lines using a starting pattern and an ending pattern, e.g.
if (/BEGIN PATTERN/ ... /END PATTERN/)
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:
Code 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;}
---------------------- 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! Susan

In reply to pattern matching by sliles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.