Hi there all,
Have a small but very confusing problem regarding differing behaviour
on Windows and Linux formats. The following code to concatenate pairs
of lines from a file works completely as expected on Windows:
# Get all the lines into a list.
my @lines_list = <INFILE>;
# Set our loop variable.
my $loop = 0;
while ($loop < @lines_list) {
my $first_line = $lines_list[$loop];
my $second_line = $lines_list[$loop + 1];
my $two_lines = '';
# If our first line is a blank (i.e. a newline character) skip.
if ($first_line eq '\n') {
$loop++;
print STDOUT "Skipping blank line.\n";
next;
}
if (defined($second_line)) {
# Not EOF.
if ($second_line eq '\n') {
# Second line is a blank line, so we only use the first.
$two_lines = $first_line;
} else {
# Set up our two line variable with a space inbetween.
chomp($first_line);
$two_lines = "$first_line $second_line";
}
} else {
# Second line is undefined, so use first alone.
$two_lines = $first_line;
}
# Make corrections in the line.
$two_lines = &make_corrections($two_lines);
(more code here...........)
It's the chunk:
# Set up our two line variable with a space inbetween.
chomp($first_line);
$two_lines = "$first_line $second_line";
which seems to work differently on my Linux machine. To demonstrate,
on Windows the following occurs:
First line is "Here is the first line..."
Second line is "and the second"
So $two_lines would become "Here is the first line... and the second".
On my Linux box however, $two_lines is set to " and the
secondline...". So essentially the space and the second line are being
pasted over the top of the first line! I'm baffled to be honest. Any
help hugely appreciated.
Thanks,
Dan Harris