Greetings Monks.

I'm trying to stretch the head a bit and advance through the next plateau, but as you know, that's not always easy. I have a module (Product::Datafile) that creates an object. That datafile object in turn has ten or so objects of type (Cobol::Copybook).

My low-tech way, which seems valid was have a new entry in the hash containing a reference for each copybook. That's a legit thing to do I believe:

$self->{'cpy00'} = Cobol::Copybook->new( {filehandle => \*DATA, filter => '00'}); $self->{'cpy01'} = Cobol::Copybook->new( {filehandle => \*DATA, filter => '01'}); $self->{'cpy04'} = Cobol::Copybook->new( {filehandle => \*DATA, filter => '04'});

Now, striving to 'think right', I realized that I can't be Lazy and loop through these copy books 'cause they're not in a data structure like they should be. My 'loop' would have to be hard-coded, and edited whenever a new copybook comes online.

So, I want to have a hash keyed on name, with values being references to copybook objects. I know it's the old HofH trick but I'm on a bit of sensory overload with the extra dynamics of OO code and I just can't see clearly. Here's what I tried:

$self->{'copybooks'} = { 'cpy00' => Cobol::Copybook->new({filehandle => \*DATA, filter => '00 +'}), 'cpy01' => Cobol::Copybook->new({filehandle => \*DATA, filter => '01 +'}), 'cpy04' => Cobol::Copybook->new({filehandle => \*DATA, filter => '04 +'}) };
That looks right to my not-so-confident eye, but my pal Data::Dumper gives:
$VAR1 = { 'cpy04' => bless( { 'filter' => '04', 'fh' => \*Product::Datafile::DATA }, 'Cobol::Copybook' ), 'cpy01' => bless( { 'filter' => '01', 'fh' => $VAR1->{'cpy04'}{'fh'} }, 'Cobol::Copybook' ), 'cpy00' => bless( { 'filter' => '00', 'fh' => $VAR1->{'cpy04'}{'fh'} }, 'Cobol::Copybook' ) };

The references are all borken, and I *know* things aren't correct, espeically with the cross-references between '00', '01', and '04'. Seeing the bless() is kinda weird too, right?

PS: I'd appreciate better title suggestions. Please /msg me with suggestions if you have one.


In reply to Hash of References in an Object by pboin

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.