when i run:
perl -e '$x="abc\nxyz\n123"; $x =~ s/\n.*/... multiline.../; printf("str %s\n", $x);'
I expect the result to be as follows:
str abc... multiline...
instead i get
str abc... multiline... 123
Where am I going wrong?
$x =~ s/\n.*/... multiline.../s
/stells Perl to treat the matched string as single-line, which results in .matching newlines. This usually does not lead to observable behavior.
/s
.
You need to use the 's' modifier for your regular expression, so dot '.' will match any subsequent newline. So:
$x =~ s/\n.*/... multiline.../;
Becomes as follows:
$x =~ s/\n.*/... multiline.../s;
Source: https://habr.com/ru/post/1707211/More articles:What do the numbers in a multi-part email mean? - emailSet permission in QTCapture? - cocoaЕсть ли способ использовать константные переменные в определениях других констант? - cIE does not clear subsequent floats - cssWPF. Какие условия должны быть выполнены, чтобы использовать привязку данных в элементах пользовательского элемента управления? - wpfLoadLibrary error: exception of first chance 0xC0000139 (DLL not found) - How to debug? - c ++In PHP, can I get the total number of case statements in a switch statement? - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1707214/how-to-load-static-data-in-mirth-avoid-many-roundtrips-to-a-database&usg=ALkJrhimYGx8ssmsI0-AMTRUm-baPsXr3wIs a lambda expression from this possible? - c #List of training topics - c ++All Articles