Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: s///g within m//g regions

by ikegami (Patriarch)
on Nov 09, 2021 at 13:48 UTC ( [id://11138615]=note: print w/replies, xml ) Need Help??


in reply to s///g within m//g regions

s{ ( ^ \#[ ]START \n ) ( .*? ) ( ^ \#[ ]END \n ) }{ $1 . ( $2 =~ s/^[ $]*//rg ) . $3 }xsmeg;

Replies are listed 'Best First'.
Re^2: s///g within m//g regions
by almr (Sexton) on Nov 09, 2021 at 15:52 UTC

    Yes! Except the above breaks, because the inner s/// kills the existing capture groups. So, those must be saved. E.g.

    s{ ( ^ \#[ ]START \n ) ( .*? ) ( ^ \#[ ]END \n ) }{ my @m = @{^CAPTURE}; $m[ 0 ] . ( $m[ 1 ] =~ s/^[ #]+//rmg ) . $m[ 2 ]; }xmesg;

      @{^CAPTURE} is new to me!

      (hmm, I wonder if String::Substitution can be optimized on version where this is available.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found