in reply to hash of objects

Each value of your %reg_hash contains a reference to an array with one element—a Register object (I'm assuming you plan to have arrays of more than one object in the future). Here's where you try to use it:

$curr_reg = new Register(); $curr_reg = \$reg_hash{IRQEN};

This creates a new Register object and then immediately destroys it, replacing it with \$reg_hash{IRQEN}. That winds up being a reference to a scalar that contains a reference to the array in %reg_hash. What you'd want is this:

$curr_reg = $reg_hash{IRQEN}->[0];

That way, $curr_reg is the object you're looking for.

If you want to loop through every object in the hash's array, you could do that this way:

foreach my $reg ( @{$reg_hash{IRQEN}} ) { $reg->print; }

Hope this helps. Have a look at perlreftut for a tutorial on references.

Replies are listed 'Best First'.
Re^2: hash of objects
by Stucked (Initiate) on Mar 23, 2007 at 07:44 UTC
    Hi Kyle,

    Thanks for your solution this is exactly what I was looking for
    Now I can access any register object in my hash using its name ;o) sweet!