From: Ben Crane <[EMAIL PROTECTED]>
> Hi all,
>
> One quick Q about hashes:
>
> they contain a key and data?
> e.g: %stuff=(A => 'one',
> B => 'two');
>
> where A and B are keys to data one and two...but what
> happens if you have a massive text file wher you had
> one key, but 20 or 30 columns of data?
>
> do you do this:
> %stuff=(A => 'one', 'two', 'three'...etc?
%stuff=(A => ['one', 'two', 'three',...]);
The value of $stuff{'A'} must be a scalar. But a reference to an
array is also a scalar. Therefore you can store references in hashes.
See
perldoc perlref
perldoc perldsc
> And is it true that hashes are a lot quicker than
> arrays? if so, how much quicker? therefore if this is
> the case, hashes seem like a default "storage unit"
> over arrays, unless you have a relatively small array
> you need to search?
This depends on the ussage.
The difference between hash and array is that array is indexed by
integers (from 0 to N), while hashes are indexed by strings.
$array[1]
is quicker than
$hash{1}
but testing whether an array contains a certain item is of course
much slower than testing whether something is a key in a hash.
Both arrays and hashes are usefull, but it's not that easy to write
here when to use which one. It depends on the data and on the
operations you need to do with it.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]