Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Finding a Block of Text in a Larger Block of Text

by kennethk (Abbot)
on Oct 13, 2011 at 16:28 UTC ( [id://931303]=note: print w/replies, xml ) Need Help??


in reply to Finding a Block of Text in a Larger Block of Text

I would suggest breaking this down as follows:
  1. Write a parser that transforms a generic ADD RULE statement into a useful data object. This could just be a hash/hashref or an object (see Moose) if you want more functionality. This will allow you to more easily determine if objects have similar content.
  2. Read in the full rule set and treat it one rule at a time. This is definitely a TIMTOWTDI moment. I would enable slurp mode (local $/;, see $/ in perlvar) and then split the input into blocks and iterate over them (for (split /\n(?=ADD RULE$)/m) {...}), stashing the parsed objects into an array for later comparison. You could easily accomplish this a number of different ways.
This should give you plenty to get started.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-18 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found