in reply to Maintainable code is the best code Part II
If you have more than ten or twenty fields (whose format I usually cut 'n paste from some document), I find the explicit use of unpack unmanagable (e.g. adding/deleting, or changing the length of a field in the middle of the format is a pain, e.g. when there's a typo in the doc or the doc includes 'sub-fields' which are not obvious), and I like to use Parse::FixedLength, which for your example would be:
my $parser = Parse::FixedLength->new([qw( first:2 second:4 filler:4 third:4 )]); my $href = $parser->parse($line); print "$href->{first}\n"; etc.
|
|---|