Updated with a little more code and comments.

Is there some reason you are not using File::Find for this?

I have added some sample, untested code for you below. I have no idea what your code is doing, but I hope the following will help you do it better.

#!/usr/bin/perl -w use strict; use File::Find; my $dir = "/Wherever my .txt files are stored"; my ($qnum, $code, $ctext, $ntext, $stext) = ('', '', '', '', ''); find(\&processfile, ("$dir/")); sub processfile { if (/(.*)\.txt$/i) { open QIN, "$_" or die $!; open QOT, ">$1.txt" or die $!; while (<QIN>) { chomp; s/\222/'/g; s/\226/-/g; if (/^Col/i) { s/^col.//gi; s/\(net\)//gi; $ntext = $_; print QOT "net1$ntext (net);unl1\n"; } elsif (/^\(S/i) { (undef, $stext) = split(/\s/, $_, 2); print QOT "net2$stext (subnet);unl1\n"; } elsif (/^[0-9]/) { ($code, $ctext) = split(/\s/, $_, 2); print QOT "n01$ctext;c=(&txt($code.ge.1)\n"; } } close QIN; close QOT; open (QIN, "$1.tmp") or die $!; open (QOT, ">$1.axe") or die $!; 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 QOT $_; } } close QOT; } }

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