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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |