in reply to Newline Problem
Untested...
#!/usr/bin/perl my $MaxLineLength = 8060; $search = '<COLUMNS>'; $replace = '<DATA>'; $searchEnd = '</COLUMNS>'; $replaceEnd = '</DATA>'; $fileContents = ''; my $first = 0; while (<STDIN>) { chomp; # print "\n" if $first++; if (/(^<DATA>\t).*(<\/DATA>$)/) { if (length() <= $MaxLineLength) { print "\n" if $first++; print; } } elsif (/(^<COLUMNS>\t).*(<\/COLUMNS>$)/) { s/$search/$replace/g; s/$searchEnd/$replaceEnd/g; print "\n" if $first++; print; } }
The key is to print out a newline at the beginning of each input line, unless it's the very first line, and also to remove the newline from the input (via chomp) so we don't print it out later.
Update: Code update as per frodo72's comments - that'll learn me for reading the question without reading the code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Newline Problem
by polettix (Vicar) on Jun 30, 2005 at 15:09 UTC |