Perhaps you could show us the code that you have at present and a very small sample of data that demonstrates the problem. The code below may be a good starting point (you'll have to fill in bits though):
use strict;
use warnings;
my $data = <<DATA;
this is a good \
nice day but not a good nice \
night
DATA
open my $IN, '<', \$data;
...
while (<$IN>) {
...
}
close $IN;
with the intent being that you fill in the ... bits to match your current code with the code above providing a nice framework for the sample.
Perl is environmentally friendly - it saves trees
| [reply] [d/l] |
Here is one way to do it by setting $/ = '' to read the lines in paragraph mode (see perlvar) and then substituting out the eol characters:
#!/usr/bin/perl -w
use strict;
$/ = '';
while (<DATA>) {
next unless /\S/;
chomp;
s{\\\n}{}g;
print "Line: ", $_,"\n";
}
__DATA__
this is a good \
nice day but not a good nice \
night
This is a test line
This is a another test \
Line
This is \ a final test line
Which prints:
Line: this is a good nice day but not a good nice night
Line: This is a test line
Line: This is a another test Line
Line: This is \ a final test line
--
John.
| [reply] [d/l] [select] |
while (<>) { # read line
while (s/\\$/ /) {
# while the current line ends with \
# replace it by blank and append a new line.
chomp; # thanks to ww
$_.= <>;
}
Update: the chomp should do it. Thanks to ww
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
| [reply] [d/l] [select] |
while (s/\n/ /s) { # remove the newlines
my $out = $_;
print $out;
}
Tested, more-or-less using GrandFather's "framework" (below). And just BTW or nitpicking, your (Skeeve's) comment "append a new line" would perhaps be clearer or less ambiguous if written as "append the next line from DATA.
The problem (yep, this is the caveat) is that with multiple sets of data (which I infer from the OP's 'ignoring all the lines which are blank or contain just "space".') this still doesn't separate the sets, as does jmcnamara's, below, qv (and ++). | [reply] [d/l] |
To begin with, single quotes don't allow most escape-codes, including newlines. So in your example, $_ = '[^\\]\n', you must use double-quotes:
$_ = "[^\\]\n";
With single quotes, your string will have backslashes and letter-n characters in them.
-- [ e d @ h a l l e y . c c ]
| [reply] [d/l] [select] |