> Sorry for the bonehead question, but I have a hash called %p_mod.  I 
> want to make a copy of it and edit the copy so that %p_mod stays the same.
> 
> Currently, I'm creating %p_mod, writing
> 
> %custom = %p_mod;
> 
> to make a copy of %p_mod in %custom and then doing a bunch of stuff to 
> %custom.  However, when I then print out %p_mod using Data::Dumper, 
> %p_mod has changed to reflect the changes in %custom.
> 
> What do I do to make an independent copy of %p_mod called %custom 
> without having to generate two separate hashes at the same time?
> 

There is something you're not telling us about the contents of these
hashes.

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

my %p_mod;
my %custom;

%p_mod = ( alpha => 'One',
           bravo => 'Two',
           charlie =>  'Three' );

%custom = %p_mod;

$custom{alpha} = 'Uno';
$custom{bravo} = 'Dos';
$custom{charlie} = 'Tres';

print Dumper \%p_mod, \%custom;

Produces the output


perl /tmp/fizz.pl 
$VAR1 = {
          'alpha' => 'One',
          'bravo' => 'Two',
          'charlie' => 'Three'
        };
$VAR2 = {
          'alpha' => 'Uno',
          'bravo' => 'Dos',
          'charlie' => 'Tres'
        };
[EMAIL PROTECTED] - ~ % 

My best guess (since you make us guess) is that you're looking for a
deep copy because the values of %p_mod are actually references.

--L



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