in reply to Look ahead and join if the line begins with a +

This works as well...
#!/usr/bin/perl -w use strict; my $last_line; my $i; my $num_lines; open(FILE, "<test.txt") || die "Unable to open file: $!"; chomp(my @lines = <FILE>); # get the lines close(FILE); $num_lines = @lines; for($i=0; $i < $num_lines; $i++) { if($i == $num_lines-1) { # make sure we don't access # uninitialized index of array print "$lines[$i]\n"; # print the last line } elsif($lines[$i+1] =~ m/\+/) { # look ahead $lines[$i+1] =~ s/^\+//; print "$lines[$i] $lines[++$i]\n"; } else{ print "$lines[$i]\n"; } }
Hope this helps. -Eric

Replies are listed 'Best First'.
Re: Re: Look ahead and join if the line begins with a +
by Rhodium (Scribe) on Apr 11, 2002 at 14:42 UTC
    I like this solution. It someowhat does what I want..but what about multiple "+" lines..
    This is a test + this + that
    So this won't work nicely.. But I worked with this one for awhile and tried to get it right..
    Thanks anyway.