Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Nice thinking, here is some thought I have.

I see three classes here:
  1. Parser
  2. Filter
  3. Formatter
The data would flow in this direction: Parser => Filter => Formatter.

  1. The Parser takes a stream of characters, and parses it into structured data.

    The Parser would have methods allow you to provide the input, which is the entity would be processed. It might be a file, might be a string...

    The Parser would parse the input into records (could be the same as lines), and each line into fields. You would allow the user to specify some criteria, and define how the records would be extracted, and then how to seperate each record into fields. Those criteria might regexps.

    For example, if we look at the sample data you give, you might want to make each line into a record, and within each record, the part before ':' is one field, the part after is another field.

    The Parser should also have methods allow you to fetch records, and fields, which would be used by the Filter.

  2. The Filter would accept structured data come out from the parser.

    You would allow the user to define the criteria as what would be threw away, and what can pass thru the Filter. Again, regexps might be a good fit here.

    The Filter does not modify the structure of the input data, but the number of output records could be less than the number of input records, if some records are threw away by the Filter.

  3. The Formatter would take the structured data, format them back to stream. Of course, the stream is formatted, and well presented.

    A good way is to allow the user define call back function, and the call back function would format those records, not your module, but your module might provide default format method, if one is not provided by the user.

I am thinking it would be really nice, if you found a way to wrap around those well known HTML parsers, and XML parsers, and make them available to your Filter.

One thing you may want to do, is to have a generic Filter class as the root, and have some generic method defined. Base on this, you then have some more specific Filters, for example, you may have one filter understand the output from a certain xml parser.

You said that you didn't want someone to do it for you, but only want some ideas. The fact is nobody can do this for you ;-), quick and good.


In reply to Re: My first package - need help getting started by pg
in thread My first package - need help getting started by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found