I have the following text file that I want to modify using Perl (this is just a text file I am reading in): ------------------------------------------------------
select (name) { //want to delete this { brace case(a=b): { // delete this { brace if (d=e) { // keep this { brace for if loop call pgmA; return rc; } // keep this } brace for if loop } // delete this } brace default: { // delete this { brace call pgmB; } // delete this } brace } // change the last } brace to END;
I want to delete some of the left curly braces (but not all) and change the last closing brace } to an "END;" so that the modified text looks like:
select (name) case(a=b): if (d=e) { ----->keep this opening brace in call pgmA; if loop return rc; } ----->keep this closing brace default: call pgmB; END; ----->change last } to END;
Can anyone suggest a solution? I know how to search for patterns, but I cannot figure out how to change the occurrence of some characters but not to change other occurrences of it. Thanks for your time, Susan

In reply to Re: parsing question 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.