Greetings Esteemed Monks,

While I was mopping the chapel floor this morning after Matins (or was it Lauds?) I had an epiphany. Actually I have this one quite often-- it is the nagging suspicion that I am doing something simple very much the long way 'round. I have a laughably simple program which is making my job much easier, but I think it can and should be better.

I have a number of *.txt files in directory, and I am doing something to each of them in turn. I currently use a file called "qcode" that lists each of the files I need processed, without the *.txt extension, thus:

q2
q5
q7
q23

What I am wondering is, is there another way to get at this, if I know that all the *txt files in the directory are the ones I want to process? At the end of this process I get these same *txt files saved as *.axe files with my changes. Here's my code-- as always, comments are appreciated.

#!/usr/bin/perl use strict; use warnings; my ($qnum,$code,$ctext,$ntext,$stext); open (QLIST, "qcode") || die "Can't open qcode file: $!\n"; while (<QLIST>){ chomp $_; $qnum="$_"; open (QIN, "$qnum.txt") || die "Can't open $qnum.txt file: $! +\n"; open (QOUT, ">$qnum.tmp") || die "Can't open $qnum.tmp file: +$!\n"; while (<QIN>){ s/\222/'/g; s/\226/-/g; chomp ($_); if (/^Col/i){ s/^col.//gi; s/\(net\)//gi; $ntext = $_; print QOUT "net1$ntext (net);unl1\n"; } elsif (/^\(S/i){ (undef,$stext) = split(/\s/,$_,2); print QOUT "net2$stext (subnet);unl1\n"; } elsif (/^[0-9]/) ($code,$ctext) = split(/\s/,$_,2); print QOUT "n01$ctext;c=(&txt($code.ge.1)\n"; } else {}; } } close QIN; close QOUT; open (QIN, "$qnum.tmp") || die "Can't open $qnum.tmp file: $!\n"; open (QOUT, ">$qnum.axe") || die "Can't open $qnum.axe file: $!\n"; while (<QIN>){ open (QIN, "$qnum.tmp") || die "Can't open $qnum.tmp file: $!\n"; + open (QOUT, ">$qnum.axe") || die "Can't open $qnum.axe file: $!\n +"; while (<QIN>){ if (/n01\s+nothing|n01\s+don't know|n01\s+other/i) { s/\n/;nz;nosort\n/g;} if (/ \s+[\w;]/){ s/n01\s+/n01/g; s/net1\s+/net1/g; s/net2\s+/net2/g;} if (/^net1misc/i){ s/unl1/unl1;nz;nosort/g;} unless (/^n01;c=|^net. /i){ print QOUT $_; } } close QOUT; }

One final note-- another question really. When I run this with "use warnings" I get a gazillion warnings reading: "Use of uninitialized value in concatenation (.) or string at oeaxe.p line 23, <QIN> line 784." I don't have any idea what this means, and my output files look fine, so I'm considering just commenting this line out for when other people use the program. Should I be more worried about this?

Thanks as always for the enlightenment.

Pax vobiscum,

NovMonk


In reply to There is more than one way (and mine is not the best) 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.