in reply to Ugly variable-length record handling
Other things can be done in general to streamline your code a little bit -- fewer variables, fewer lines of code, less open/close overhead on the temp file:
open( DAT, '<', 'export.dat' ) or die "Open for read failed on export.dat: $!"; my $tmp; # file handle while ( <DAT> ) { next unless ( /\S/ ); if ( /^1/ ) { if ( defined( $tmp )) { output_data( $tmp ); } open( $tmp, '+>', 'export.tmp' ) # open read/write, truncate +first or die "Open failed for export.tmp: $!"; } print $tmp $_; } output_data( $tmp ); sub output_data { my $fh = shift; seek( $fh, 0, 0 ); # rewind to start of file # do stuff with export.tmp contents... close $fh; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ugly variable-length record handling
by Melly (Chaplain) on Jan 04, 2007 at 09:58 UTC |