On Jan 17, 2004, at 2:16 PM, Dan Anderson wrote:

On Sat, 2004-01-17 at 15:12, James Edward Gray II wrote:
On Jan 17, 2004, at 2:02 PM, Dan Anderson wrote:

On Fri, 2004-01-16 at 11:03, Jack Chen wrote:
Hi,

I don't know how to work with this data structure:

my @array = ((a         =>   'appple'),
             (b         =>   'tree'),
             (c         =>   'chair'));

That "array" is an array of hashes.

It was probably meant to be, but it is not as written. Look again.

Ahhh, you're right. Correct me if I'm wrong, but the arrays expand out,
so although (a -> 'apple') is a hash and (b => 'tree') is a hash, it
actually contains the hash:

You're terminology is a little confusing, but I think you have the right idea.


('a', 'apple')          # this is a list, not an array or a hash
(a => 'apple')               # this is the exact same list

(a => 'apple', b => 'tree') # this is just a bigger list
# and because Perl flattens all nested lists...
((a => 'apple'), (b => 'tree')) # this is the same as the above, just one big list


my @array = ((a => 'apple'), (b => 'tree')); # makes a four element array
my %hash = ((a => 'apple'), (b => 'tree')); # makes a two key hash


Hope that clears things up.

James

(
  a => 'apple',
  b => 'tree',
  c => 'chair',
)

Correct?

-Dan




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to