> %{$array[1]}{'Item'} = $something;

Close...

try
${$array[1]}{'Item'} = $something;

The only way you can (safely) add a "hash" to an array (or inside another
hash) is to use a hash reference. Of course Perl gives you several ways to
do this :-)

You declare a hash REFERENCE like this:

        $hashref = {
                hashkey => 'hashvalue'
        };

Note the { }, instead of ( )

To set an element of an array to a hashref, you can do

        $array[1] = {
                hashkey => 'hashvalue'
        };

To change (or retrieve) the value in a hash, you can do (see perlref
manpage):

        $$hashref{newkey} = 'newvalue';
          OR
        $hashref->{newkey} = 'newvalue';

Both of these mean the same thing:
        $$hashref and $hashref-> mean 'dereference the reference $hashref'
        {...} means 'expect the reference to be a reference to a hash'

You can substitute $hashref with $array[1] like this:

        ${$array[1]}{newkey} = 'newvalue';
          OR
        $array[1]->{newkey} = 'newvalue';

Note the braces { } in ${$array[1]}.
$$array[1] is interpreted as: $$array means dereference the reference
$array, and the [] means 'expect the reference $array to point to an array'.
No wonder you have a headache... I get a headache just writing this :-)

i.e.
        # store a hash in the array @array
        ${$array[1]}{newkey} = 'newvalue';
        print $array[1]->{newkey};

        # store a hash in the array referenced by $arrayref
        $$arrayref[1]{newkey2} = 'newvalue2';
        print $$arrayref[1]{newkey2};
        print $arrayref->[1]{newkey2};

Sticking to the -> notation is less prone to give headaches (though only
slightly).
Read the perlref manpage (about half a dozen times) until it all sinks in...

Zoltan.


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to