in reply to Feedback request for text file manipulator

Overall, it looks like you're writing pretty sensibly. Just a couple of minor things I noticed:

These assignments:

@text = "g total";
should really have the right side in parentheses, IMO. It just makes me cringe to have mismatched assignments.
$ntext = (split (/;/)) [0]; $ntext =~ s/n01//g;
Do you really want a global replacement? It would be clearer to do this as one extraction:
($ntext) = /^n01([^;]+)/; # or /^n01(.+?);/;
You've got useless (though not harmful) quoting here:
print OUT "$_";
and it could be written as just:
print OUT;
And since it's part of every branch of your if, you might as well just move it outside the whole conditional and get rid of the else clause.

About your plans for future development. Instead of reading all the lines into an array, I would recommend you stop keeping track of @gcard and @pcard, since they never really change. They're entirely dependent on corresponding elements in @text. So just accumulate @text as usual (without any truncation, and put all your column-width processing into the printing section after the while loop. Calculate the sum of the lengths of text, determine how wide each column can be, and then format all your output accordingly.


The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Feedback request for text file manipulator
by NovMonk (Chaplain) on Mar 26, 2004 at 21:09 UTC
    Thanks a lot for the clear explanations. This in particular sent me to the various manuals and references until I could translate for myself why they do what you suggest:

    ($ntext) = /^n01([^;]+)/; # or /^n01(.+?);/;

    Tried to msg you with my thanks, but the space in your user name sent my comment to "roy" instead. Hopefully this will reach you.

    Pax,

    NovMonk

    Oh-- I msg'ed duff directly-- but he deserves public thanks as well, so here it is.