Quick fix, you can work to beautify it:
#!/usr/bin/perl my $MaxLineLength = 8060; $search = '<COLUMNS>'; $replace = '<DATA>'; $searchEnd = '</COLUMNS>'; $replaceEnd = '</DATA>'; $fileContents = ''; my $linePrefix = ''; while (<STDIN>) { chomp; # Remove newline if (/(^<DATA>\t).*(<\/DATA>$)/) { if (length() <= $MaxLineLength) { print $linePrefix; # Empty only for first line print; $linePrefix = "\n"; } } elsif (/(^<COLUMNS>\t).*(<\/COLUMNS>$)/) { s/$search/$replace/g; s/$searchEnd/$replaceEnd/g; print $linePrefix; print; $linePrefix = "\n"; } }
Basically, you remove newlines from what you read in, then output newlines before printing a line, not after. The only exception is the first line, of course.

As you may imagine, I'm too lazy to test it - basically because I don't want to write an example file :)

OFF-TOPIC Update: note that your node had been considered in order to remove the ------------------------------------------------ line at the beginning of the script. This is due to the fact that in Unix-like environments having #!/usr/bin/perl at the very beginning (I mean, starting from the first character) allows automatic selection of the interpreter. You can edit and remove them by yourself :)

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re: Newline Problem by polettix
in thread Newline Problem by doublek321

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.