in reply to Newline Problem
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.#!/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"; } }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Newline Problem
by ikegami (Patriarch) on Jun 30, 2005 at 16:15 UTC | |
by doublek321 (Initiate) on Jul 05, 2005 at 19:52 UTC |