in reply to Jumping out of a partially read file
One thing I should mention here is this. Setting $/ simplifies things greately. But! If you're processing large files (you mentioned something about them being 40MB) then you better be sure they all contain those headers that you're talking about. If not, the whole file will be slurped into memory.local $/ = "HEADER END\n"; # set input record separator while ($file = <*.las>) { open(FILE, $file) || die "Couldn't open $file : $!\n"; my $header = <FILE>; close(FILE); # process $header here }
Hope this helps. --perlplexermy $maxHeader = 50; OUTER: while ($file = <*.las>) { open FILE, $file or die "Couldn't open $file : $!\n"; my $header = ''; while (<FILE>){ $header .= $_; last if $_ eq "HEADER END\n"; if ($. > $maxHeader){ print "Invalid file format : $file\n"; close FILE; next OUTER; } } close FILE; # process $header here }
|
|---|