> The output of the following script:
>
> #!/usr/bin/perl -w
> @array = [0, 1, 2, 3];
> $hash{0} = @array;
> print "array = @array\n";
> print "hash = ", $hash{0}, "\n";
>
> is:
>
> array = ARRAY(0x8d13c20)
> hash = 1
>
> I expected the results to be the same. Why aren't they?
First thing is, you're making an array to a reference to an anonymous
array. That's almost pointless :P The assignment to the hash :
$hash{0} = @array;
is only going to give you the number of elements inside of the array
(due to hashes always having scalar key/value pairs).
Here is a program for you to go over, hope it helps. :)
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $array = [1,2,3,4];
my %hash = @{$array};
print "Array Reference in Scalar: $array\n\tHash structure:\n";
for (sort keys %hash) {
print "\t$_\t=>\t$hash{$_}\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/