use strict; use warnings; my $row =""; my $inarray=0; while (<DATA>) { chomp; s/^\s+//; # <-- New line added <---- if (/^array|^unassigned/){ print "$row\n" if $inarray; $row=$_; $inarray=m/^array/; next; } next unless $inarray; $row .= " $_"; } print "$row\n" if $inarray; __DATA__
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
In reply to Re^9: Join multiple lines in a string based on regex.
by NetWallah
in thread Join multiple lines in a string based on regex.
by pr33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |