in reply to perl crashes parsing huge script - how to find a line that crashes it?
It was tested on the following file (but not on Windows):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; }
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).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";
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).
|
|---|