Re: hash defining



Ben Marsh wrote:
%hash = ( "key" => {"key1" => value} );

To define a hash use () brackets the second hash is inserting not a hash but a
reference to a hash so you use {} brackets.

You refer to 'value' it as $hash{key}->{key1}. $hash{key} is a scalar
contains a reference pointing to a hash (so $hash{key}->{ }) and the
key is key1 (so $hash{key}->{key1}).

Regards,

Ben Marsh

You can also use $hash{key}{key1} = value; What notation you use is up to you.

--

Just my 0.00000002 million dollars worth,
--- Shawn

"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle

"The man who sets out to carry a cat by its tail learns something that
will always be useful and which will never grow dim or doubtful."
Mark Twain

"Believe in the Divine, but paddle away from the rocks."
Hindu Proverb

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/

.



Relevant Pages

  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Net::SFTP::Attributes
    ... when I ask a simple question on the correct usage of a module I would ... If $subref is specified, for each entry in the directory, $subref will ... be called and given a reference to a hash with three keys: ...
    (comp.lang.perl.modules)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Hashes of Hashes
    ... group = STRING ... If I swap the order of the declarations, then all of the keys for the ... hash that is referenced by $Data. ... This is known as a "symbolic reference" - using the ...
    (perl.beginners)
  • My own handy Pocket Reference notes
    ... inside the covers of my Perl Pocket Reference over the years. ... To pass a only single hash to a subroutine: ...
    (comp.lang.perl.misc)