I don't know much about how Perl deals with this stuff, but what
you've done is made a copy of the pointer/reference.
Both variables are referencing the same memory/hash.
What you want to do is copy the hash, not copy the reference to it.
I /think/ this ought to work:
my %hash = %{$fileSize};

__CODE__
my $h1 = {a=>1,b=>2};
print join(", ", keys %{$h1}), "\n";
my $h2 = $h1; # References same object
$$h2{c} = 3;
print join(", ", keys %{$h1}), "\n";
%copy = %{$h1}; # Copy to a new has
$copy{d} = 4; # Doesn't affect the original object
print join(", ", keys %{$h1}), "\n";
print join(", ", keys %copy), "\n";
__OUTPUT__
a, b
c, a, b
c, a, b
c, a, b, d
__END__

You can then reference the new copy if you so desire.
my $refToCopy = \%copy;

On Thu, Mar 6, 2008 at 10:42 AM, Dermot <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  I have a file with a few settings in, a hash of settings.
>
>  EG:
>
>  use strict;
>  use warnings;
>  our @EXPORT = qw($fileSize);
>
>  our $fileSize = { a=> {name => 'small', size => 50}, b=>{name=> 'medium',
>  size => 75,} c=>{name=> 'large', size => 100} };
>
>  These settings are used by several different programs and I don't always
>  want to apply all the settings. I thought I could do this:
>
>  # Make a local copy of HoH
>  my $ref = $fileSizes;
>
>  # remove a hash via key c
>  delete $ref->{'c'};
>
>  Print the original structure
>  print Dumper($fileSizes);
>
>  When I do this I get the reference without the C hash! I'm sure this is by
>  design, I'm sure there is a good reason for it but how keep a version
>  private?
>
>  Hope

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


Reply via email to