As for the second question, the answer is yes and no.  As far as the
programmer is concerned for the most part the basic difference between
arrays and hashes is that hashes have named keys, but you will normally use
them in different situations.  They are also stored differently, but I
admittedly don't know the details there.

     Arrays, for example, are often more suited for situations in which you
need to store a list of things that have something in common.  Perhaps they
are all lines of a file, or perhaps they are usernames, or words in a
string.  I've always thought that in a sense an array is like a hash with
one key and multiple values.  (If that confuses you just forget it, because
the way I see things is not always the most intuitive way for everyone
else).  

     A hash is a good way to keep a list of items in which each key is
associated with its value in the same way.  In your example, you can use the
hash to call up an object by referring to its color.  For this reason, you
will sometimes hear them referred to as "Associative Arrays".

-----Original Message-----
From: Ahmed Moustafa
To: [EMAIL PROTECTED]; Sa
Cc: [EMAIL PROTECTED]
Sent: 3/31/02 5:04 AM
Subject: Re: Newbie Help please.

Sa wrote:
> #!/usr/bin/perl -w
> $map{"red"} = "apple";
> $map{"green"} = "grass";
> $map{"blue"} = "ocean";
> print "A string please: "; chomp ($some_string = <STDIN>);
> print "The value for $some_string is $map($some_string)\n";
> 
> When I run it though I get the following complaint from perl:
> 
> A string please: blue
> Use of uninitialized value in concatenation (.) at ./key3.pl line 6,
<STDIN>
> line 1.
> The value for blue is (blue)


In line 6, it's $map{$some_string} not $map($some_string).

Regards,
-- 
Ahmed Moustafa
http://pobox.com/~amoustafa


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to