in reply to Working with fixed length files
Besides looking at it like pairs of records of 122 bytes, you could look at it as records of 244 bytes.
local $/ = \(2*122); binmode($fixedfile); while (<$fixedfile>) { my @fields = unpack( "A2 A10 A33 A15 A19 A10 A3 A18 A6 A4 x2" . "A2 A98 A11 A9 x2", $_ ); ... my $total = $fields[3]; my $timestamp = $fields[4]; ... }
Replace "A" for "x" if you want to ignore a field.
As for how to store the fields, you could use a hash or scalars.
my %fields; @fields{qw( ... total timestamp ... )} = unpack(...);
my ( ... $total, $timestamp, ... ) = unpack(...);
Update: Added mention of "x".
Update: Added alternative storage strategies.
|
|---|