Here's a barely tested script which may find more or less where the offending bits are:
use File::Temp; my $file = shift @ARGV; my $low=1; chomp(my $high = `wc -l $file`); print "File is $high lines\n"; my %tried; while (my $next=int(($high-$low)/2)+$low) { last if $tried{$next}++; print "low: $low high: $high next: $next\n"; my $tmp = File::Temp->new(TEMPLATE => "tmp_XXXXXX", DIR=>"."); open(my $fh, $file) or die "Can't open $file: $!"; while (<$fh>) { print $tmp "__END__\n" if $. == $next; print $tmp $_; } close $fh; $tmp->close(); my $out = `perl -c $tmp 2>&1`; ( $out =~ /syntax OK/ ? $low : $high ) = $next; }
It was tested on the following file (but not on Windows):
use strict; use warnings; my $foo=1; BEGIN { die "Dead\n" } print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n"; print "hello\n";
This assumes you have the unix command "wc" installed (which you can get if you install msys, though you can work around this in pure perl with a bit more code).

Update: I can think of ways this will fail, e.g., if the __END__ line splits up a {...} block you'll get a syntax error which may not have anything to do with the problem you're looking for which will throw this method off...oh, well...back to the drawing board (more testing around the "perl -c" output for those kinds of errors might do the trick, but I'm all out of tuits).


In reply to Re: perl crashes parsing huge script - how to find a line that crashes it? by runrig
in thread perl crashes parsing huge script - how to find a line that crashes it? by Anonymous Monk

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.