bliako has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I can not understand why this works:
my $x = <<'EOX'; A { B 123 C xyz } EOX $x =~ s/A\s*\{.+?\}//s; print "x='$x'\n"; # empty
but this does not (linux terminal):
perl -pe 's/A\s*\{.+?\}//s' <<'EOX' A { B 123 C xyz } EOX # prints exactly what the input is
I have checked if there are mistaken shell interpolations to the oneliner script, but there are not, I think:
x='s/A\s*\{.+?\}//s' echo $x # s/A\s*\{.+?\}//s
Edit: the same problem if the oneliner operates on a file:
cat > infile<<'EOX' A { B 123 C xyz } EOX perl -pe 's/A\s*\{.+?\}//s' infile # or perl -i -pe 's/A\s*\{.+?\}//s' infile
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why dot does not match newline in oneliner but it does in script, with /s modifier?
by hippo (Archbishop) on Oct 24, 2025 at 14:50 UTC | |
by bliako (Abbot) on Oct 24, 2025 at 21:22 UTC |