On Tue, 17 Jul 2001, Chuck Morford wrote:
> And about Pascal's Record Type. Is there anything equivalent in Perl
> without getting into OOP?
Linked lists are really not necessary in Perl since you can do cool things
with lists that you can't do in Pascal or C. However, I think for what
you are doing, you want to create an array or a hash of references, and
no, they do not get converted to strings. A reference IS already a
scalar, and is the only way to create complex data structures in Perl:
my $adventure = {
players => { ranger => 'Aragorn',
thief => 'Bilbo',
halforc => 'Shagrat'
},
realms => [ 'Mordor', 'Eriador', 'Beleriand' ]
};
So now you have a hash reference containing a hash reference keyed by
'players' and an array reference keyed by 'realms'.
$new_ranger = $adventure->{players}->{ranger}; #gives 'Aragorn'
$new_realm = $adventure->{realms}->[1]; #gives 'Eriador'
BTW, _Mastering Algorithms with Perl_ from O'Reilly has several chapters
devoted to complex data structures, including linked lists. If you want
to translate your typical Pascalish CompSci stuff to Perl, this is a good
book to start with.
-- Brett
http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Parts that positively cannot be assembled in improper order will be.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]