Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: text processing

by sundialsvc4 (Abbot)
on Apr 22, 2014 at 18:22 UTC ( #1083213=note: print w/replies, xml ) Need Help??

in reply to text processing

This sort of problem is, actually, extremely common.   It is, in fact, the inspiration for the awk tool that was one of the original inspirations for Perl.

In general, problems like this one can solved “text line by text line,” and can be reduced, algorithmically speaking, to four cases, all of which can (somehow) be recognized by the contents of the line (and/or by “beginning of file” and/or “end of file”):

  1. A record which marks the start of some area-of-interest.   Such as, in this case, TABLE.
  2. A record which marks the end of an area (and the generation of output based on accumulated data), such as END.
  3. A record which marks data to be gathered in-memory in anticipation of future output, such as DATAnn.
  4. A record whose presence is expected but otherwise uninteresting, such as HEADn.

Your immediate requirement could actually be addressed entirely by awk, and nothing else, and perhaps for this very reason you might elect to do so.   In any case, the man-page hyperlinked above should now be read carefully and thoroughly.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1083213]
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-06-25 08:29 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.