On Fri, Jun 12, 2009 at 22:22, Chap Harrison<c...@pobox.com> wrote:
> I've created a complex, nested  data structure that is, at its outermost
> level, a hash:  %qa.  It collects QA statistics for a school.
>
> Now I want to be able to process multiple schools in one run, so I've
> created another hash, %sch_qa, whose key is School Name and whose value is a
> ref to *a copy of* %qa.
>
> Assuming $sch_name is the name of the school, I wrote this:
>
> if ( ! exists $sch_qa{$sch_name} )  {
>        %{$sch_qa{$sch_name}} = %qa;
> }
snip

If you need to make a deep copy a data structure you should use the
dclone function from the Storable[1] module:

use Storable qw/dclone/;

#lots of code

unless (exists $sch_qa{$sch_name}) {
    $sch_qa{$sch_name} = dclone \%qa;
}

1. http://perldoc.perl.org/Storable.html#MEMORY-STORE

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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