pboin has asked for the wisdom of the Perl Monks concerning the following question:
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:
That looks right to my not-so-confident eye, but my pal Data::Dumper gives:$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 +'}) };
$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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash of References in an Object
by dragonchild (Archbishop) on May 26, 2005 at 13:23 UTC | |
|
Re: Hash of References in an Object
by Joost (Canon) on May 26, 2005 at 13:29 UTC | |
|
Re: Hash of References in an Object
by LanceDeeply (Chaplain) on May 26, 2005 at 14:36 UTC | |
|
Re: Hash of References in an Object
by GoCool (Scribe) on May 26, 2005 at 19:37 UTC |