If you want to store an array inside a hash value you have to store a reference 
to it, not the actual array. Here are two examples :

my %hash;
my @arr = split(...);
$hash{'key'} = \@arr;

Or shorter :

$hash{'key'} = [ split(...) ];

Cheers dude!

-- biskofski

Sent from my iPad

On  Jul 20, 2011, at 11:34 PM, "H Kern" <g...@pbwe.com> wrote:

> Just a followup on that last one...
> 
> I'm using this code thinking that ($header{"info}) will be an array of all 
> the elements in the string that was read in.
> 
> The first print statement does what I hope, printing out the elements of that 
> array as a string.
> But, when the perl compiler gets to the second print statement, it balks.
> 
> "Can't use string ("HDR  QuickBooks Premier      Version 2"...) as an ARRAY 
> ref while "strict refs" in use at..."
> This makes me think that in the fourth line '( $header{"info"} ) = 
> split(/\t\n/, <>);'  $header{"info"} is actually getting set to a string of 
> the concatenation of the parts split apart by the split function. Is this 
> true?
> 
> If so, then how do I set the hash table element header{"info"} to be the 
> array of elements created by the split() function?
> 
> ... and, can the elements of that array be accessed using the syntax I use in 
> the second print statement?
> 
> Thanks, --H
> 
> code:
> 
> my %header;
> 
> ( $header{"keys"} ) = split(/\t\n/, <>);
> ( $header{"info"} ) = split(/\t\n/, <>);
> 
> print $header{"info"} . "\n";
> print $header{"info"}[0] . "\n";
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to