[ABE.pm] data structures within data structures
Ricardo SIGNES
rjbs-perl-abe at lists.manxome.org
Fri Dec 31 11:45:59 CST 2004
* Faber Fedor <faber at linuxnj.com> [2004-12-31T11:04:05]
> I want to create an array/hash that contains in each row variables and
> arrays. If I have two vars and an array, it might look something like
> this:
>
> my $ds =( {"1", "2", (a,b,c,d) },
> {"3", "4", (e,f,g) },
> {"5", "6", (h,i,j,k,l) }
> );
If "ds" is an array, you need to use @ds, not $ds. If it is a scalar,
you need to use [] not () to create an array reference to store in it.
You can't use {} to put non-hash-references inside @ds. Your lists,
there, are not indexed by name, they're positional, so they're array
references. Use [].
A list like "(a,b,c,d)" can't be a member of an array, you need to use a
reference.
You don't need to quote numbers. You do need to quote letters. You can
use the qw() operator to create a list of quoted words, and then
reference it by enclosing it in [].
my @ds = (
[ 1, 2, [ qw(a b c d ) ] ],
[ 3, 4, [ qw(e f g ) ] ],
[ 5, 6, [ qw(h i j k l) ] ]
);
To access the letter 'g', you would say: $ds[1][2][2].
$ds[1] is [ 3, 4, [ qw(e f g) ] ]
$ds[1][2] is [ qw(e f g) ]
$ds[1][2][2] is 'g'
--
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20041231/a628b0bd/attachment.bin
More information about the ABE-pm
mailing list