in reply to parsing long text file

If it were me, I'd build a search-and-replace hash, then go against that for each row.

my %replace = ( iapw_p1 => "P1 = (inquiry, launch page)\n", iapw_p2 => "P2 = (car coverages, endorsements, operators)\n", iapw_p3 => "P3 = (notepad, scratch)\n" ) ; while ( <> ) { foreach my $key ( keys %replace ) { s/$key/$replace{$key}/g ; } print ; }

_______________
D a m n D i r t y A p e
Home Node | Email

Replies are listed 'Best First'.
Re: Re: parsing long text file
by Anonymous Monk on Jun 18, 2002 at 17:58 UTC
    It seems like a better idea, do you think it will parse faster? Here is the code again with a better display. Where would you improve it? Thanks a lot again!
    my $start = $getdata; my $end = $getdata2; my $dir = '../weblog/'; @ARGV = (); die "start must be less than end" if $start >= $end; die "no dir $dir here" unless -d $dir; find sub { my $numb = (fileparse($_,'.txt'))[0]; return unless $numb =~ /^\d+$/; push @ARGV, $File::Find::name if $numb >= $start and $numb <= $end; }, $dir; die "no .txt files found in $dir" unless @ARGV; while ( <> ) { $p1="P1 = (inquiry, launch page)\n"; $p2="P2 = (car coverages, endorsements, operators)\n"; $p3="P3 = (notepad, scratch)\n"; $b1="B1 = (my inquiry: auto, home and location)"; $p0="P0 = (local search)\n"; $c0="C0 = (dist search)\n"; $c1="C1 = (state inquiry)\n"; $c3="C3 = (test notepad)\n"; $h1="H1 = (owners and coop search and history)\n"; if (m/iapw_p1/g){s/iapwp1/$p1/g; print;} if (m/iapw_p2/g){s/iapwp2/$p2/g; print;} if (m/iapw_p3/g){s/iapwp3/$p3/g; print;} if (m/iapw_b1/g){s/iapwb1/$b1/g; print;} if (m/iapw_p0/g){s/iapwp0/$p0/g; print;} if (m/iapw_c0/g){s/iapwc0/$c0/g; print;} if (m/iapw_c1/g){s/iapwc1/$c1/g; print;} if (m/iapw_c2/g){s/iapwc3/$c3/g; print;} if (m/iapw_c3/g){s/iapwh1/$h1/g; print;} }
Re: Re: parsing long text file
by Anonymous Monk on Jun 18, 2002 at 18:27 UTC
    Just to let you know that I tried to parse it using your idea and still hangs. I don't know what to do with it.

      You may have already considered this, but are you sure that the program is hanging, and not just taking a long time to process 300KB? If you add $|++; near the beginning of your program, you can prevent the program from buffering the output. I don't know if this will help you any, but it's worth a try. :-)


      _______________
      D a m n D i r t y A p e
      Home Node | Email