Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
dmmiller2k is right.
You also want to be sure that the 'text' that you are reading is examined as a single string, by your matching pattern (not one line at a time).
Then the regex is pretty simple (but note the /s operator is added, as dmmiller2k advised).
#!/usr/bin/perl -w use strict; #examine DATA as a single string. $/ = ''; while (<DATA>){ #'.' will match \n with the /s operator if ( m/if.+else/s ){ s/{//; s/}//; } print; } __END__ if (c=e) { #// delete this curly brace call pgme; call pgmd; } else { call pgmd; #// keep these curly braces call pgmc; } if (c=e) { #// delete this curly brace call pgme; call pgmd; } else { call pgmd; #// keep these curly braces call pgmc; }

mkmcconn
update please note that this regex example is
for illustration only - it's easily broken and the reason
it appears to work is because of the structure of the data
example.

In reply to Re: pattern matching by mkmcconn
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found