Greetings, Kind Monks,

First, I have a confession-- about a month ago I received some great clues from graff, Belgarion, cLive;-), revdiablo, and punkish concerning this node. I usually thank people who help me out, but this time, illness, life and other misfortunes delayed me. So, I say now, thanks very much, you fellows are a credit to the community, and I'm really sorry for not saying it sooner.

Now for my question. I've written a script that works interactively with vi to add some code to a text file. The text file starts out something like this:

l ban n10total n01first line n01second line --- (more lines) n01fifteenth line (approx) l ban2 ... (variations on above)

When I get done, I get this:

l ban1 tstat propmean;elms=ABC (etc); n10 n01first line;ID=A n01second line;ID=B --- (etc) n01fifteenth line;ID=Q l ban2 tstat (line as above) n10total n01first line;ID=A (etc.)

What I need help with is this-- I'd like each tstat line to only show the letters I'm using in the n01 lines below it, for the stuff between one l ban line and the next. I'd also like it to error out if the number of n01 lines in any section (defined as one line beginning with l and the next such line-- there can be any number of such sections in the file, though probably, not more than 3 or 4) exceeds the number of available letters in my array @letters. And I'd like it to do this without munching my text file.

Here's my code:

#!/usr/bin/perl use warnings; use strict; use diagnostics; #array @letters is all letters except O,I,L (not used in this process) my @letters = qw/A B C D E F G H J K M N P Q R S T U V W X Y Z/; my $count = 0; while (<>){ if (/^[Ll]/){ s/\n/\ntstat propmean;elms=AB,CDEFGHJKMNPQRSTUVWXYZ;clevel=95,90;p +ropcorr\n/g; $count = 0; } if (/^[Nn]01/){ s/\n/;ID=$letters[$count]\n/; $count++; } print $_; }

It's very simple stuff, but I am still fairly new and clueless. I assume I need to completely revamp my thinking, if my two enhancements are possible at all. I would appreciate not only ideas but explanations of what I could be doing better. And this time, I'll be more prompt in thanking you for the wisdom.

Pax,

NovMonk


In reply to Request for comments/ clues on simple text manipulation script by NovMonk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.