in reply to Re^2: Modifying pos() from within (?{...})
in thread Modifying pos() from within (?{...})

I already answered in the second thread, that the $input has an extra \n at the end, and I just realized why. The funny thing is, I reached that conclusion for the wrong reason. When I did my test I didn't modify $/ and didn't call chomp, so the \n wasn't removed. You, on the other hand did have chomp, but with $/ set to undef. The chomp doc states:

When in slurp mode ($/ = undef ) or fixed-length record mode ($/ is a reference to an integer or the like; see perlvar), chomp won't remove anything.

So in my tests by forgetting to call chomp, I got the same result you had by disabling its effect, and therefore reached the correct conclusion :D

  • Comment on Re^3: Modifying pos() from within (?{...})

Replies are listed 'Best First'.
Re^4: Modifying pos() from within (?{...})
by AnomalousMonk (Archbishop) on Apr 27, 2018 at 16:31 UTC
    When in slurp mode ... chomp won't remove anything.

    Another illustration of the wisdom of local-ized modification of globals in the narrowest scope, e.g.
        my $input = do { local $/;  <DATA>; };
    rather than in broad or, indeed, global scope even when "it's just a small program; it doesn't really matter what we do to globals": spooky action at a distance.


    Give a man a fish:  <%-{-{-{-<