when I run:
perl -e '$x="abc\nxyz\n123"; $x =~ s/\n.*/... multiline.../; printf("str %s\n", $x);'
I expect result to be:
str abc... multiline...
instead I get
str abc... multiline...
123
Where am I going wrong?
when I run:
perl -e '$x="abc\nxyz\n123"; $x =~ s/\n.*/... multiline.../; printf("str %s\n", $x);'
I expect result to be:
str abc... multiline...
instead I get
str abc... multiline...
123
Where am I going wrong?
$x =~ s/\n.*/... multiline.../s
/s
modifier tells Perl to treat the matched string as single-line, which causes .
to match newlines. Ordinarily it doesn't, resulting in your observed behavior.
You need to use the 's' modifier on your regex, so that the dot '.' will match any subsequent newlines. So this:
$x =~ s/\n.*/... multiline.../;
Becomes this:
$x =~ s/\n.*/... multiline.../s;