regex - Why am I still getting newlines? -
i have following code:
open input, "input.txt"; $line = ""; while (<input>) { $line = $_; $line =~ s/\s+^//; print $line; } but output still includes newlines. have tried \v , \r.
/\s+^/ means "one or more whitespace characters before start of string" — never match.
if goal remove trailing whitespace characters, need $ rather ^:
$line =~ s/\s+$//; (and if goal remove trailing newline, should use the built-in chomp function.)
Comments
Post a Comment