in reply to Re: Re: Dreaded Symbolic References
in thread Dreaded Symbolic References
In order to avoid potential mismatches of the field name and pack template values, I would think about using a hash to generate both the unpack template and the field names. The only problem is hashes are not stored in any particular order. To combat this, one could store the "hash" in an array, and separate the keys and values "manually." Example:
my @fields = qw(Year A2 Month A2 Day A2 Request_Seq A4 Request_Type A2 Record_Seq A2 Record_Data A1486); my @keys = map $fields[$_], grep $_%2==0, 0 .. $#fields; my @values = map $fields[$_], grep $_%2==1, 0 .. $#fields; my %data; # bad name. we should know better. ;) @data{ @keys } = unpack join("", @values), $foo;
Alternatives to this include, but are not limited to:
|
|---|