Basic debugging checklist says use strict; use warnings; especially if you want to cut your development time in half!
It will point you at problems with your code, like this
#!/usr/bin/perl -- use diagnostics; use strict; use warnings; use Data::Dump; my %sampleHash = (); my @array1 = ('a','b','c'); my @array2 = ("x","y","z","s"); $sampleHash{"hash1"} = @array1; $sampleHash{"hash2"} = @array2; dd \%sampleHash; print $sampleHash{"hash1"}[0]; __END__ $ perl fudge { hash1 => 3, hash2 => 4 } Can't use string ("3") as an ARRAY ref while "strict refs" in use at f +udge line 14 (#1) (F) Only hard references are allowed by "strict refs". Symbolic references are disallowed. See perlref. Uncaught exception from user code: Can't use string ("3") as an ARRAY ref while "strict refs" in +use at fudge line 14.
@array in scalar context returns its size , perlintro, Tutorials: Context tutorial
To store an array in a scalar, to store an array in a hash, you have to use the reference operator, reference-of operator, see perlreftut#Making References , references quick reference
In reply to Re: Trouble accessing Hash of Arrays (troubleshooting basics)
by Anonymous Monk
in thread Trouble accessing Hash of Arrays
by sujeet97
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |