Perl / perl5

đŸȘ The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 526 forks source link

heredoc in s///e replacement #2312

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#3636 (status was 'resolved')

Searchable as RT3636$

p5pRT commented 23 years ago

From @vanstyn

Trawling through old messages\, I found this aside in   http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-01/msg01423.html

The following code gives the same results with all perls I've checked after 5.004 up to and including bleadperl (it fails to find the end of the heredoc in 5.004 and earlier)​:

crypt% ./perl -wl $_ = "test"; s/t/\<\<E/eg;   "new" E print __END__   "new" es "new"

crypt%

Hugo

p5pRT commented 23 years ago

From @tamias

On Fri\, Aug 04\, 2000 at 01​:37​:12PM +0100\, Hugo wrote​:

Trawling through old messages\, I found this aside in http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-01/msg01423.html

The following code gives the same results with all perls I've checked after 5.004 up to and including bleadperl (it fails to find the end of the heredoc in 5.004 and earlier)​:

crypt% ./perl -wl $_ = "test"; s/t/\<\<E/eg; "new" E print __END__ "new" es "new"

crypt%

What is the bug?

Ronald

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

iHugo \hv@&#8203;crypt\.compulink\.co\.uk wrote

The following code gives the same results with all perls I've checked after 5.004 up to and including bleadperl (it fails to find the end of the heredoc in 5.004 and earlier)​:

I agree with Ronald that I see no bug here. But this area is clearly full of possibilities

$ ./perl -wl $_ = 'test'; s/t/\<\<E . 'fgh' dddd eeee E . 'ijk'/eg; print; __END__ ^D Can't find string terminator "E" anywhere before EOF at - line 2. $

Note that the CTRL/D was needed - the __END__ wasn't seen.

Mike Guy

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

I wrote

Note that the CTRL/D was needed - the __END__ wasn't seen.

I should have made clear that this one *is* a bug.

And that it happens with bleadperl.

Mike Guy

p5pRT commented 23 years ago

From @vanstyn

In \20000804093955\.B476438@&#8203;linguist\.dartmouth\.edu\, Ronald J Kimball writes​: :On Fri\, Aug 04\, 2000 at 01​:37​:12PM +0100\, Hugo wrote​: :> Trawling through old messages\, I found this aside in :> http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-01/msg01423.ht :ml :> :> The following code gives the same results with all perls I've checked :> after 5.004 up to and including bleadperl (it fails to find the end of :> the heredoc in 5.004 and earlier)​: :> :> crypt% ./perl -wl :> $_ = "test"; :> s/t/\<\<E/eg; :> "new" :> E :> print :> __END__ :> "new" :> es "new" :> :> crypt% : :What is the bug?

Gak\, it's my head. I'm expecting the string to eval-and-replace to be qq{ "new"\n}\, to become qq{new} after eval​: it seems wrong that the string should be qq{\<\<E}\, since in that case it seems like the compiler should not know to attribute the heredoc to it. But I have a nasty suspicion that the compiler not knowing that was a bug I fixed myself a mere sprinkling of eons ago.

I've probably been getting too much sleep\, or something.

Hugo

p5pRT commented 23 years ago

From @tamias

On Fri\, Aug 04\, 2000 at 06​:21​:12PM +0100\, Hugo wrote​:

In \20000804093955\.B476438@&#8203;linguist\.dartmouth\.edu\, Ronald J Kimball writes​: :On Fri\, Aug 04\, 2000 at 01​:37​:12PM +0100\, Hugo wrote​: :> crypt% ./perl -wl :> $_ = "test"; :> s/t/\<\<E/eg; :> "new" :> E :> print :> __END__ :> "new" :> es "new" :> :> crypt% : :What is the bug?

Gak\, it's my head. I'm expecting the string to eval-and-replace to be qq{ "new"\n}\, to become qq{new} after eval​:

That's the result you would get if you added another /e.

Compare to this​:

$E = \<\<E;   "new" E $_ = "test"; s/t/$E/eg; print;

$_="test"; s/t/$E/eeg; print;

Ronald

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

iI wrote

I agree with Ronald that I see no bug here. But this area is clearly full of possibilities

$ ./perl -wl $_ = 'test'; s/t/\<\<E . 'fgh' dddd eeee E . 'ijk'/eg; print; __END__ ^D Can't find string terminator "E" anywhere before EOF at - line 2. $

Having thought further about this case\, and also contemplated the code to see how one might go about "mending" it\, I've come to the conclusion that it's a feature rather than a bug and that a doc fix is appropriate.

Patch is for bleadperl.

Mike Guy

Inline Patch ```diff --- ./pod/perldata.pod.orig Tue Aug 1 03:32:02 2000 +++ ./pod/perldata.pod Mon Aug 7 13:54:41 2000 @@ -462,6 +462,22 @@ down from the door where it began. FINIS +If you use a here-doc within a delimited construct, such as in C, +the quoted material must come on the lines following the final delimiter. +So instead of + + s/this/<
p5pRT commented 11 years ago

From @cpansprout

On Sun Aug 06 23​:02​:25 2000\, RT_System wrote​:

iI wrote

I agree with Ronald that I see no bug here. But this area is clearly full of possibilities

$ ./perl -wl $_ = 'test'; s/t/\<\<E . 'fgh' dddd eeee E . 'ijk'/eg; print; __END__ ^D Can't find string terminator "E" anywhere before EOF at - line 2. $

Having thought further about this case\, and also contemplated the code to see how one might go about "mending" it\, I've come to the conclusion that it's a feature rather than a bug and that a doc fix is appropriate.

Patch is for bleadperl.

Mike Guy

--- ./pod/perldata.pod.orig Tue Aug 1 03​:32​:02 2000 +++ ./pod/perldata.pod Mon Aug 7 13​:54​:41 2000 @​@​ -462\,6 +462\,22 @​@​ down from the door where it began. FINIS

+If you use a here-doc within a delimited construct\, such as in C\<s///eg>\, +the quoted material must come on the lines following the final delimiter. +So instead of + + s/this/\<\<E . 'that' + the other + E + . 'more '/eg; + +you have to write + + s/this/\<\<E . 'that' + . 'more '/eg; + the other + E + =head2 List value constructors

List values are denoted by separating individual values by commas

End of patch

Well that’s very interesting. That was never applied\, which I think is fortunate\, as Larry Wall specifically made nested here-docs *not* work that way in commit fd2d09532.

--

Father Chrysostomos

p5pRT commented 11 years ago

From @cpansprout

On Sat Aug 18 23​:32​:16 2012\, sprout wrote​:

On Sun Aug 06 23​:02​:25 2000\, RT_System wrote​:

iI wrote

I agree with Ronald that I see no bug here. But this area is clearly full of possibilities

$ ./perl -wl $_ = 'test'; s/t/\<\<E . 'fgh' dddd eeee E . 'ijk'/eg; print; __END__ ^D Can't find string terminator "E" anywhere before EOF at - line 2. $

Having thought further about this case\, and also contemplated the code to see how one might go about "mending" it\, I've come to the conclusion that it's a feature rather than a bug and that a doc fix is appropriate.

Patch is for bleadperl.

Mike Guy

--- ./pod/perldata.pod.orig Tue Aug 1 03​:32​:02 2000 +++ ./pod/perldata.pod Mon Aug 7 13​:54​:41 2000 @​@​ -462\,6 +462\,22 @​@​ down from the door where it began. FINIS

+If you use a here-doc within a delimited construct\, such as in C\<s///eg>\, +the quoted material must come on the lines following the final delimiter. +So instead of + + s/this/\<\<E . 'that' + the other + E + . 'more '/eg; + +you have to write + + s/this/\<\<E . 'that' + . 'more '/eg; + the other + E + =head2 List value constructors

List values are denoted by separating individual values by commas

End of patch

Well that’s very interesting. That was never applied\,

Actually\, it *was* applied\, as 8bd33e3ebe. But it has never been fully true.

which I think is fortunate\, as Larry Wall specifically made nested here-docs *not* work that way in commit fd2d09532.

And it wasn’t just nested here-docs. It was here-docs inside any quoted construct. That was accidentally broken later on in a2c066523a\, except in string evals (or multiple levels of nested quotes)\, where here-docs fully nested in quote-like operators continued to work\, the crash introduced in 0244c3a403 (which only crashed for s/// without /e) notwithstanding.

So I think we should remove that documentation.

--

Father Chrysostomos

p5pRT commented 10 years ago

From @rjbs

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2012-08-19T17​:42​:42]

And it wasn’t just nested here-docs. It was here-docs inside any quoted construct. That was accidentally broken later on in a2c066523a\, except in string evals (or multiple levels of nested quotes)\, where here-docs fully nested in quote-like operators continued to work\, the crash introduced in 0244c3a403 (which only crashed for s/// without /e) notwithstanding.

So I think we should remove that documentation.

I believe I understand correctly\, and therefore agree.

-- rjbs

p5pRT commented 10 years ago

From @cpansprout

On Sun Jul 21 13​:35​:12 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2012-08- 19T17​:42​:42]

And it wasn’t just nested here-docs. It was here-docs inside any quoted construct. That was accidentally broken later on in a2c066523a\, except in string evals (or multiple levels of nested quotes)\, where here- docs fully nested in quote-like operators continued to work\, the crash introduced in 0244c3a403 (which only crashed for s/// without /e) notwithstanding.

So I think we should remove that documentation.

I believe I understand correctly\, and therefore agree.

I did so in 1bf4876033. BTW\, have you seen \https://rt-archive.perl.org/perl5/Ticket/Display.html?id=109744#txn-1230929 yet?

--

Father Chrysostomos