Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Using Look-ahead and Look-behind

by Corion (Patriarch)
on Nov 28, 2024 at 06:18 UTC ( [id://11162925]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Look-ahead and Look-behind
in thread Using Look-ahead and Look-behind

You're reading your input line-by-line but you're trying to match across lines. That won't work.

The following should work, reading the input all at once (see perlrun):

perl -g -i -pe ’s/(?<=look)\n(?=ahead)/-/g;’ myfile.txt

Replies are listed 'Best First'.
Re^3: Using Look-ahead and Look-behind
by akiemr19 (Initiate) on Nov 28, 2024 at 13:24 UTC

    Thank you very, very much for setting me on the right path! While (in my environment) the -g switch isn't allowed for (what I learned to be was) slurping, instead using the -0777 switch did work nicely. I had seen this switch before, but until now wasn't aware of its usage until I dug deeper, prompted by your input.

    I was stuck on this for a long time - thanks again for the quick response!

    P.S. I just found where version 5.36 would allow the use of the -g switch, which is apparently a shortcut for using -0777.

      The -g only came in with perl 5.36 so won't be available in many LTS platforms unless they backport it. Using -0777 as you have mentioned is perfectly fine and, AFAIAA, will continue to be.


      🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11162925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2026-03-07 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.