Assigning a reference shares the same data, while copying a hash makes a separate top-level hash.

Shallow Copy and Mutation

shallow_copy_mutation.pl
use strict;
use warnings;

my $new_status = ;
my $original_ref = { status => "open" };
my $alias_ref = $original_ref;
my $copy_ref = { %{$original_ref} };

$alias_ref->{status} = $new_status;

my $original_status = $original_ref->{status};
my $copy_status = $copy_ref->{status};

print "new_status=$new_status\n";
print "original=$original_status\n";
print "copy=$copy_status\n";
use strict;
use warnings;

my $new_status = ;
my $original_ref = { status => "open" };
my $alias_ref = $original_ref;
my $copy_ref = { %{$original_ref} };

$alias_ref->{status} = $new_status;

my $original_status = $original_ref->{status};
my $copy_status = $copy_ref->{status};

print "new_status=$new_status\n";
print "original=$original_status\n";
print "copy=$copy_status\n";
use strict;
use warnings;

my $new_status = ;
my $original_ref = { status => "open" };
my $alias_ref = $original_ref;
my $copy_ref = { %{$original_ref} };

$alias_ref->{status} = $new_status;

my $original_status = $original_ref->{status};
my $copy_status = $copy_ref->{status};

print "new_status=$new_status\n";
print "original=$original_status\n";
print "copy=$copy_status\n";
shallow copy A shallow copy duplicates the top-level container but not deeper nested values.