Hi,
this code parses the input linewise and prints directly to STDOUT, so you can redirect the result to another file.
while ( my $line = <DATA> ) { chomp $line; # remove the spaces from start of line if ( $line =~ s/^\s+// ) { # print line if successful replacement print $line; } else { # print newline (not for first line) print "\n" if $. != 1; print $line; } } __DATA__ first second third first second third first second first
Update:
shorter version:
while ( my $line = <DATA> ) { chomp $line; # remove the spaces from start of line if ( ! ( $line =~ s/^\s+// ) ) { # print newline (not for first line) print "\n" if $. != 1; } print $line; }
In reply to Re: Appending lines starting with white space to the previous line
by linuxer
in thread Appending lines starting with white space to the previous line
by ashok13123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |