in reply to Array in a Hash

Okay, I did a little bit of research on my own to add to what you have given me... But what is the difference between these two snippets of code?:


boo_radley's way, using @{$db{'key1'}{'key2'}[0][0]} = "one_value";, produces this hash:

%db = ( 'key1' => { 'key2' => [ [ ['one_value'], ['two_value'] ], [ ['three_value'], ['four_value'] ] ] } );


mstone's way, using $db{'key1'}{'key2'}[0][0] = "one_value";, produces this hash:

%db = ( 'key1' => { 'key2' => [ [ 'one_value', 'two_value' ], [ 'three_value', 'four_value' ] ] } );


The only difference between the two is that referencing it as an array (@{$db{...}}) adds square brackets around the values. But what difference does this create in reading/storing values?

(Hash printout via Data::Dumper)

UPDATE: So, I should use mstone's code?

Replies are listed 'Best First'.
Re: Re: Array in a Hash
by boo_radley (Parson) on Dec 14, 2001 at 19:50 UTC
    I was actually being bad-lazy; I copied the assignments from the original node without examining them too closely. The square brackets make array refs.