Hmm... perl's ease has led me down a horrible path yet again. Well not so horrible, but you'll see.

I come from a C/C++ background, so when I want to create an ADT (advanced data type), I use struct or class. It's so easy.

I want to create a heterogenous data structure in perl, and I would appreciate some input -- currently I'm getting an error about coercing a hash into an array (or was it an array into a hash ... :)

Here's a quick summary of what I need:

Example Keep track of Varies by
0 Index Subdirectory ... File ... Measurment
ParserObject1 Parser Subdirectory ... File
HRT Name Measurement
Heart Rate Label Measurement
PRFN1 Conditions constant
Low-Hour VFR Groups constant
Heart rate < 50 Invalid data constant
0404 -> 1 Substitutions constant

For the invalid data, I thought that the value could be something like this --

[ ['measurement1', [ ['test subject number', 21, 27], ['value', 50], ... ], ... ], ... ]

Where 21 was the min, 27 the max, etc.

I'm not sure that any of that is needed by you, so I'll stop there.

However, my current method of referring to these data is as such:

$info->{subdirectory}->{file}->[measurement] = INDEX; $info->{subdirectory}->{file} = PARSER; $info->[measurement]->{name} = NAME; ...etc., according to what it varies by...

My question to you: Is this, as I suspect, the source of the 'hash coercion problem'? and if so, what data type should I make ... possibly should I go all out and make a module with accessors and constructors and the full nine yards, etc.?

Your experience and help is most apprecieted. </CODE>

The actual things I need to keep track of are changing somewhat as I'm becoming aware of what I need ... your answer need not be too specific to the data I have, though it could.


In reply to Help with ADT by dimmesdale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.