How do we preserve the data as three unique arrays? An array can only contain scalars. Luckily we know that a reference is a scalar. Let's create an array of array references!
# we have separate arrays we want to combine
my @austin_toys = qw(perl pizzastone pilobolus);
my @justin_toys = ('hack saw', 'boots', 'grout');
my @reinhard_toys = ('OED', 'oatmeal', 'orange juice');
# we could do this: (an array of array refs)
my @toys = ( \@austin_toys, \@justin_toys, \@reinhard_toys );
print "Reinhard's 1st toy is a $toys[2]->[0]\n";
print "Reinhard's 1st toy is a $toys[2][0]\n";
# or this: (an array ref of array refs)
my $toys = [ \@austin_toys, \@justin_toys, \@reinhard_toys ];
print "Reinhard's 1st toy is a $toys->[2][0]\n";
Tuesday, September 25, 2007
Arrays of Arrays
Subscribe to:
Post Comments (Atom)
1 comment:
Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Dieta, I hope you enjoy. The address is http://dieta-brasil.blogspot.com. A hug.
Post a Comment