Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Accessing an array of anonymous hashesby thezip (Vicar) |
on Mar 26, 2007 at 16:58 UTC ( [id://606617]=perlquestion: print w/replies, xml ) | Need Help?? |
thezip has asked for the wisdom of the Perl Monks concerning the following question: I'm working on a problem where I have to produce a fixed-length string (record) that is comprised of N columns, each of varying width. ie.: my $str = "AAABBBBBBBBC";where: "AAA" represents the value for "Batch_Agency""BBBBBBBB" represents the value for "Batch_Date" "C" represents the value for "Batch_Type" I'm concerned with these two data:
Once I get the data structure right, I'll use pack to produce the format specification and the fixed-length record. I began setting up my data structure by creating the array of anonymous hashes as shown below in method 1:
This was not very useful, since I wasn't able to come up with a way access the field name and column position array using this method. If I change the data structure, I can successfully access the required elements by using either method2 or method3:
Since my knee-jerk reaction was to set up the data structure using method1, I'd like, if possible, for someone to explain to me how to access the fieldname and column position array ref for each field using method1. Thanks! Updated: Data structure in method2
Back to
Seekers of Perl Wisdom
|
|