On Fri, Apr 4, 2008 at 12:16 PM, Rascal <[EMAIL PROTECTED]> wrote:
> I am using Perl 5.8.5 on Red Hat Linux.
>
> The output of the following script:
>
> #!/usr/bin/perl -w
> @array = [0, 1, 2, 3];
snip
This is creating an array with one element. The element is a
reference to an array that holds the list (0, 1, 2, 3). What you want
to say here is
my @array = (0, 1, 2, 3);
snip
> $hash{0} = @array;
snip
Hashes and arrays can only hold scalars. When you place an array in
scalar context it returns the number of elements it holds. What you
need to do is store a reference to an array. If you want changes to
$hash{0} to effect @array you say
$hash{0} = [EMAIL PROTECTED];
and if you want to only store a copy of what is in @array you say
$hash{0} = [EMAIL PROTECTED];
snip
> print "array = @array\n";
> print "hash = ", $hash{0}, "\n";
snip
The second print statement should be
print "hash = @{$hash{0}}\n";
to dereference the array reference in $hash{0}. You should read about
references and complex data structures like HoA (hash of arrays) in
the following perldocs:
http://perldoc.perl.org/perlreftut.html
http://perldoc.perl.org/perldsc.html
http://perldoc.perl.org/perlref.html
You can also access the docs from the command line with the perldoc command:
perldoc perlreftut
perldoc perldsc
perldoc perlref
You can learn more about perldoc by typing
perldoc perldoc
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/