Hi folks I am not an expert in perl but correct me if I am wrong -
Seeing your question and your considerations below, indeed you seem
not to be an expert in perl. So I guess you're not wrong.
is it true you can use a hash and work with it just as you would an
array - what are the differences between them (besides in an array you
can have a multidimensional array) ?
You can also have multidimensional hashes. But both are not "real"
multidimentional beasts. However for the moment don't bother...
Really hashes are associative arrays, i.e. they are a finite mapping
between a set of _keys_ and a set _values_. The keys are generic
strings. An array is a mapping between a finite set of natural numbers
of the form {0,... , n} (if you don't set $[ to something other than
0, but again, don't bother!) and a set of values.
why arent folks using hashes instead of arrays since (I believe) they
are faster to access and take up the same or less memory than arrays..
You will certainly know that in perl conversions between numbers and
strings happen automagically all the time. So indeed you may use a
hash to implement an array. However hashes are called like that
because their implementation is based on hash tables that provide
means to quickly search through the keys. There's no particular
general advantage when the keys are simple numbers instead.
So use an array when you need a mapping from a finite set of numbers
to some values, except possibly when the mapping is very sparse. How
much is "very", may depend on many factors, and I don't know the lower
limit exactly. Surely I would use a hash if I need to *explicitly* set
the mapping amongst say 100 numbers uniformely distribuited in
0..100_000_000 and some values. I don't have the vaguest idea how well
the hashing algorithm would hash such keys, but the thing can be
investigated...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,