Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have to format a report from two piped outputs. These outputs contain a header section and content section with several columns. My question is how can i extract only selected columns from these outputs, sort them, and remove their headers? Thanx a lot, pls. email me at royv@cdo.philcom.com.ph for your reply.

Replies are listed 'Best First'.
Re: Output Formatting
by chromatic (Archbishop) on Mar 08, 2000 at 23:35 UTC
    I would build a hash of lists. The headers (containing column names?) would be the hash keys, and the values would be anonymous arrays constructed from each row. A list of lists would work too, if you are comfortable using column indexes instead of names.

    When you extract columns, access the anonymous list (via index, in a list of lists or via column name in a hash of lists), do a simple sort on it, and you will have your data. See perldoc perldsc for information on how to build and to access complex data structures. You'll end up with something like:

    my %columns = { "name" => [ 'bob', 'jim', 'fred' ], "age" => [ '23', '44', '54' ], "hair" => [ 'blond', 'brown', 'none' ] };
RE: Output Formatting
by Anonymous Monk on Mar 09, 2000 at 01:21 UTC
    A little more information would make it easier to offer a suggestion. Could you supply a few lines of sample output, (disguised if necessary; layout and type of content are more important than actual values, unless some constant can be used to discriminate between types of line)?
Re: Output Formatting
by stephen (Priest) on Mar 09, 2000 at 06:14 UTC