On Wed, 2006-29-03 at 23:45 -0800, John W. Krahn wrote:
> Michael Gale wrote:
> > Hello,
> 
> Hello,
> 
> >     I have setup a hash like the following:
> > 
> > my $test;
> > 
> > $test->{$setup}->{'opt'} = "OK";
> 
> Or:
> 
> my $test = { $setup => { opt => 'OK' } };

Or:
  my $test{$setup}{opt} = 'OK';

> 
> > It works fine, now I want to save an array to the hash:
> > 
> > my @data;
> > 
> > push(@data,"test");
> > 
> > $test->{$setup}->{'data'} = @data;
> 
> That should be:
> 
> $test->{ $setup }{ data } = [ @data ];
> 
> Or:
> 
> @{ $test->{ $setup }{ data } } = @data;

Be aware that these two statements do a top-level copy of @data:
  $test{$setup}{data} = [ @data ];
  @{ $test{$setup}{data} } = @data;

Whereas this one stores a reference to @data:
  $test{$setup}{data} = [EMAIL PROTECTED];

The difference is that in the first two, if @data changes,
$test{$setup}{data} does not. In the second, it will. Consider what
effect you want in your program when you choose between them.

-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them,
we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to