[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Re: Newlines (fwd)



At 2:47 PM -0500 10/17/97, Mark Manning/Muniz Eng. wrote:
>According to John Macdonald:
>>
>> actually arrays.  It's not so necessary now that perl has support for
>> references and real multi-level arrays, but it is still useful for saving
>> things in a file and later reading it back in.
>
>REAL multi-level arrays?  Eh?  What page of the book is
>this on?  I'd like to read up on this!  This isn't the
>"fake out Perl" stuff is it?  :-?

Try Chapter 4 of the second edition.

It may depend upon your definition of "real" and "fake-out".

In perl4 and earlier, the only mechanism for "multiple keyed" values was to
use a list in the subscript in a hash:

    $hash{$key1,$key2,"abc"} = $value;

That, under the hood, was identical to joining the list of keys using the
$, variable.  So, that statement was the same as:

    $hash{ "$key1$,$key2$,abc" } = $value;

It was useful to an extent, but there were significant limits. The value of
$hash{$key1} had no relationship to the above element, for example.  The
only way to find that "abc" was one of the elements in the $key1,$key2
sub-array was to go through all of the keys of the array and match them by
hand to see if they started with "$key1$,$key2$,".

With perl5, you can have array references within any scalar, including
array and has elements, and you can chain key lookups in a multi-level
notation like $struct[5]{$name}{$address}.  And, especially, you can treat
the levels coherently - $struct[5]{$name} is something that can be used and
that usage is still refering to an item that has a hash element of $address.

Now, I chose the phrase "multi-level" carefully, and specifically did not
say multi-dimensional.  Perl's multi-level structures are physically
disjoint, unlike C multi-dimensional arrays.  But, they are just as useful.

John Macdonald             jmacd@interlog.com



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch