in reply to Clarity in parsing fixed length data.
Both of your alternatives (one-line-ish, and using a sub) are very hard to read, and require lots of duplicate code for each message type. Hide the gory details, leaving a clean interface (such as those below). This process is called encapsulation.
A procedural interface:
my $TEST_REC_FORMAT = get_msg_format [ status => 'n ', # 0 time => 'n ', # 2 date => 'N ', # 4 code => 'a16', # 8 key msid => 'a10', # 24 key ]; my %test_vals = parse_msg($TEST_REC_FORMAT, $rec);
An OO interface:
my $TEST_REC_FORMAT = MessageFormat->new([ status => 'n ', # 0 time => 'n ', # 2 date => 'N ', # 4 code => 'a16', # 8 key msid => 'a10', # 24 key ]); my %test_vals = $TEST_REC_FORMAT->parse($rec);
What exactly get_msg_format or new returns is not important. How exactly it is calculate is not important either.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Clarity in parsing fixed length data.
by runrig (Abbot) on Aug 10, 2006 at 22:17 UTC | |
|
Re^2: Clarity in parsing fixed length data.
by rodion (Chaplain) on Aug 10, 2006 at 22:42 UTC | |
by GrandFather (Saint) on Aug 11, 2006 at 00:02 UTC | |
by runrig (Abbot) on Aug 10, 2006 at 23:30 UTC | |
by rodion (Chaplain) on Aug 13, 2006 at 11:49 UTC | |
by runrig (Abbot) on Aug 16, 2006 at 19:19 UTC |