in reply to Look ahead and join if the line begins with a +
Hope this helps. -Eric#!/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"; } }
|
|---|
| 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 |