On the other hand, if you insist on reading a line-at-a-time,
let's just define lines to end on a '}';
#!/usr/bin/perl
# http://perlmonks.org/?node_id=1206966
use strict;
use warnings;
local $/ = '}';
while(<DATA>)
{
s/^war \V* \K \{ .* \}/ $& =~ tr|&\n||dr /emsx;
print;
}
__DATA__
some starting text
war eligible, init =0*DEC0, ev (VARIABLE){1*BIN0,2*DEC3,6*BIN4,
& 5*BIN43,6*DEC32,
& 5*BIN43,7*DEC32}
some other text
war wear, init =1*DEC1, ev (VARIABLE) {
& 1*BIN0,2*DEC3,6*BIN4,
& 5*BIN43,6*DEC32,
& 5*BIN43,7*DEC32,6*DEC32,6*DEC3,
& 8*BIN3,6*DEC34
}
some final text
Outputs:
some starting text
war eligible, init =0*DEC0, ev (VARIABLE){1*BIN0,2*DEC3,6*BIN4, 5*BIN4
+3,6*DEC32, 5*BIN43,7*DEC32}
some other text
war wear, init =1*DEC1, ev (VARIABLE) { 1*BIN0,2*DEC3,6*BIN4, 5*BIN43,
+6*DEC32, 5*BIN43,7*DEC32,6*DEC32,6*DEC3, 8*BIN3,6*DEC34}
some final text
-
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.