Welcome Mark.Allan,
If you loop on the file as:
my $string = "";
while ( <$IN> ) ## $IN needs to be open
{ chomp;
if ( $_ eq "END" )
{ $string = join ( " ", split " ", $string );
# $string =~ s/$other//g; ## In case you need to remove o
+ther characters
print $OUT "$string\n"; ## $OUT is open output file
$string = ""; next;
}
$string .= $_;
}
I know you didn't want code, but it was easier to type code then describe :-)
That special use of 'join' is in the Camel book (3rd edition) on page 154. It removes whitespace before and after the string, plus reduces multiple spaces to 1.
I typed this in, so there may be some typos, but it should get you going, and remember to use 'use strict; use warning;' in your code.
Hope it helps.
"Well done is better than well said." - Benjamin Franklin
-
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.
|