=>my @list; #Read first, ask questions later is probably not optimal for this #Scope our variable, merge, read, and assign all at once while(chomp(my $line = <NETLIST>)){ #Save a match, substitution returns true iff we susbtituted if ($line =~ s/^\+//){ #Append to previous line (last line in the array) $list[-1] .= $line; } else{ #Save the line push(@list, $line); } } #Map is good, nice way to get all the newlines back #join would work if you the file need not end in a newline print map {"$_\n"} @list;
=>my @list; while(chomp(my $line = <NETLIST>)){ #Trinary is good ;-) $line =~ s/^\+// ? $list[-1] .= $line : push(@list, $line); } print map {"$_\n"} @list;
my @list; #for is very perlish, so is using $_ chomp && $_ =~ s/^\+// ? $list[-1] .= $_ : push(@list, $_) for <NETLIS +T>; print map {"$_\n"} @list;
--
perl -pe "s/\b;([mnst])/'\1/mg"
In reply to Re: Look ahead and join if the line begins with a +
by belg4mit
in thread Look ahead and join if the line begins with a +
by Rhodium
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |