How do you use deep copying with a short example?

In Perl, deep copying is the process of creating a complete, independent copy of a complex data structure, such as a hash or array that may contain references to other data structures. Unlike shallow copying, which only duplicates the top-level structure, deep copying ensures that all elements are copied recursively.

Example of Deep Copying in Perl:

use Storable qw(dclone); my $original = { name => 'John', age => 30, hobbies => ['reading', 'cycling', 'hiking'], }; # Perform a deep copy my $copy = dclone($original); # Modify the copy $copy->{name} = 'Jane'; push @{$copy->{hobbies}}, 'swimming'; print "Original: ", $original->{name}, "\n"; # Outputs: John print "Copy: ", $copy->{name}, "\n"; # Outputs: Jane

deep copying Perl data structures references Storable dclone