in reply to Re: append line to previous line in txt file
in thread append line to previous line in txt file
use strict; use warnings; my $acc; while ( <> ) { chomp; if ( m{^;} ) { $acc .= substr $_, 1; } else { print $acc, qq{\n} if defined $acc; $acc = $_; } } print $acc, qq{\n} if defined $acc;
I hope this is of interest.
Cheers,
JohnGG
Update: added defined to test to cope with lines that are empty. My test file is
;ddadadwaew sddjdsoeugfuiegf euefuefuerfefg ;erreuruyegfegr ueyrueuefeyr7e ; ; erieihir eiereyrgueyrgh ;ieruherueu ;ierhueryugr reieruyeruy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: append line to previous line in txt file
by pc88mxer (Vicar) on Jul 09, 2008 at 13:34 UTC | |
by johngg (Canon) on Jul 09, 2008 at 21:23 UTC |