in reply to parsing long text file

While your implementation is a little inefficient, I don't see any problems with it. Because you are using the diamond operator (<>) to read data, that means you're running it from the command line with something like Is that right? Because if you're just using

Then I'm not surprised that it appears to be hanging -- it's actually waiting for data to arrive on STDIN so it can start to parse.

--t. alex

"Mud, mud, glorious mud. Nothing quite like it for cooling the blood!" --Michael Flanders and Donald Swann

Replies are listed 'Best First'.
Re: Re: parsing long text file
by Anonymous Monk on Jun 18, 2002 at 15:21 UTC
    Sorry I am not running it from the command line the <> operator is there but it can be replaced I am looking for a better way to parse the file; here is what I have on top of the code I send. It have to display to the browser.

    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;
      Please put CODE tags around your code so that we can read it .. that means <CODE> at the beginning and </CODE> at the end. Also, see if you can follow some kind of regular indentation: the closing brace for your subroutine (if that's what find sub is) is hidden near the end of the second line.

      Please post code that compiles cleanly and looks a little better than that, then we can check it out.

      --t. alex

      "Mud, mud, glorious mud. Nothing quite like it for cooling the blood!" --Michael Flanders and Donald Swann

        Sorry, here is the code again, thanks for your replay!
        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;} }