in reply to In a dereference nightmare!
bless(\{hash => \{}}, $class);
That blesses a reference to a reference to a hash that contains a single value that is a reference to a reference of a hash.
The { } hashref construct creates a hash reference for you, so there is no need to put a backslash in front of it. That will only create a reference to the newly created reference to an anonymous hash.
Without the backslashes:
The arrow between two sets of braces is optional, and it's not the only notation. Here are a few alternatives (less good, imho):bless { hash => {} }, $class; ... $object->{hash}->{key_inside_that};
If you don't remove the backslashes, you will have scalar references, and those can only be dereferenced with the ugly syntax:$object->{hash}{key_inside_that}, $$object{hash}{key_inside_that}, ${${$object}{hash}}{key_inside_that}
Read perlref for more information.bless \{ hash => \{} }, $class; ... ${$$object->{hash}}->{key_inside_that}; ${${${$object}}{hash}}{key_inside_that}; # etcetera...
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: In a dereference nightmare!
by dargosch (Scribe) on Apr 18, 2002 at 08:36 UTC |