Hi all,
I guess it must be a simple problem, but it's a
mystery to me.
I got 30 "fields" all separated by pipes in some files
with many many lines. Some of the fields need to be
changed, but mostly I have to drop any line that has
certain values in certain fields.
So I start by skipping any field that has garbage in
it:
open FOUT, ">>/some/path/outputfile.txt";
open FILE "</some/path/inputfile.txt";
while<FILE>{
p="N";
next if (/.*?\|value_garbage1\|.*?/ ||
/.*?\|value_garbage2\|.*?/ ||
/.*?\|value_garbage3\|.*?/);
        #and then I continue with an if
        if(/(.*?)\|(.*?)\|....30 times/){
                $p="Y";
                do something to $1; #change field 1
                do something to $3; #change filed 3
                $fld1=$newfld1;
                $fld2=$2;
                $fld3=$newfld3;
                $fld4=$4;....and so on
        }
        print FOUT "$fld1|$fld2|...|$fld30|\n" if ($p="Y");
#print the whole thing to the new output 
}

Well, it happens that some of the lines are completely
out of whack and the regex simply stops there - it
doesn't exit, no errors but goes into an infinite loop
even though I don't know how exactly is this possible.
My second if states clearly (or not so clearly) that
if the line does not have 30 fields it should skip the
block, it should NOT print anything at the handle and
should get the next line.
For whatever reason, the first time it encounters a
line with less that 30 fields, it just loops without
end.
I tried to solve this by replacing the .*? in the
references by the actual format of each field and
suddenly it started working but now the regex is a
hundred times slower and the only thing that speeds it
up is to go back to the .*? that really goes fast as
long as the regex "is true". I mean if I have 30
fields all the time, the regex works OK and it goes
very fast.

Anybody cares to explain this to me?
Thanks,
Dan 


__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to