Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by LanX (Saint)
on Nov 09, 2021 at 13:14 UTC ( [id://11138610]=note: print w/replies, xml ) Need Help??


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

> I could turn the string into a line-list, use the flip-flop to identify regions, and s///g for each line.

That's exactly what I would do. 3 lines max.

> But isn't there something cleaner and more general?

I beg your pardon? Plz define "cleaner"

You can certainly use some convoluted huge nested regex for this, which is hardly better maintainable.

(I'm sure tybalt is already preparing one)

Or an extra module with some proprietary parsing grammar. But that's only replacing one DSL with another.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: s///g within m//g regions
by almr (Sexton) on Nov 09, 2021 at 13:21 UTC
    Well, something like iterating over matches (for my $m( $str =~ m/^# START.*?^# END.*/mg ) { update_match( $m ); }.

    In this case, yes, I could reshape into a line-list, but what about other "region" definitions, and possibly multiple regions in a line?

      > but what about other "region" definitions, and possibly multiple regions in a line?

      SSCCE please :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        # turn * into - within |...| regions
        A |simple*example| is |so*simple| to come*up |with
        these*days|
        
        should become
        # turn * into - within |...| regions
        A |simple-example| is |so-simple| to come*up |with
        these-days|
        
        So, iterate over matches, and perform substs within each match.
        Thanks for all the variants, I've learned some things I've missed before and re-learned some things I've forgotten (this seems to happen every time I don't use perl for a couple of months or so).

        The problem I see with SSCCE (despite its benefits) is that it encourages "particularization" instead of generalization; so after getting example-tailored responses, one has to play whack-a-mole with them to get to the original, abstract problem / "programming malaise".

        Then again, those example-tailored responses always teach new bits of ingenuity. Anyway, thanks again.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-29 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found