Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Accessing an array of anonymous hashes

by ferreira (Chaplain)
on Mar 26, 2007 at 18:16 UTC ( #606629=note: print w/replies, xml ) Need Help??

in reply to Accessing an array of anonymous hashes

For the particular problem you're approaching, it looks like the structure of a list of pairs is quite adequate.

( Batch_Agency => { range => [ 1 .. 3] }, Batch_Date => { range => [ 4 .. 11] }, Batch_Type => { range => [ 12 .. 12 ] } }
With the list of pairs, you get the features:
  • every field has a name
  • the order is preserved
So it should be quite easy with a little processing both to format the records and to map the input given as array of hash refs to the right positions and shapes.

Beware of using the ranges as you mentioned (range => [1 .. 3]). They can become a burden to maintain as fields are added or change size. It would probably be more useful to work only with lengths and compute automatically the range (if needed). Something like length => 3 or format => 'A3'.

If you decide to avoid the suffering of writing and maintaining the code for producing these streams of fixed-format records, you may try some modules from CPAN. Among them, Data::FixedFormat and AnyData::Format::Fixed.

Replies are listed 'Best First'.
Re^2: Accessing an array of anonymous hashes
by thezip (Vicar) on Mar 26, 2007 at 18:50 UTC

    Thanks for your reply.

    As a clarification, I was told that the specification I was provided would probably never change (or would at least require an act of the Oregon State Government to change it). There are perhaps hundreds of machines that use this particular format, so I feel reasonably safe hard-coding a few things.

    My goal is to localize all of the hard-coded items in one place to minimize the risk you mention.

    As for the column ranges, this is the way they are portrayed in the specification (ie. as a range of numbers like [59 .. 63]. I plan on calculating the column widths based upon the values that I am supplied, and then constructing the pack specification from that.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606629]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2019-06-20 03:54 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (89 votes). Check out past polls.