# Hash reference and hash copy in Perl

The following program illustrates the difference between a hash reference using `\%h1` and a hash copy using `{%h2}`. If we take a reference to the hash using the backslash, `\`, then modifying the reference also modifies the contents of `%h1`. If we copy `%h2` using `{ }`, modifying the hash reference `\$hr2` does nothing to `%h2`

```#!/usr/local/bin/perl
use warnings;
use strict;
# Both %h1 and %h2 are hashes with one entry, with key "a" and value
# "b".
my %h1 = (a => 'b');
my %h2 = (a => 'b');
# \$hr1 is a hash reference to %h1.
my \$hr1 = \%h1;
# \$hr2 is a hash reference to a copy of %h2.
my \$hr2 = {%h2};
# Now change the value at key "a" in both \$hr1 and \$hr2.
\$hr1->{a} = 'c';
\$hr2->{a} = 'c';
# Here the backslash before the dollar makes it a printing character.
print "Hash which was referenced: \\$h1{a} = \$h1{a}\n";
print "Hash which was copied: \\$h2{a} = \$h2{a}\n";

```

```Hash which was referenced: \$h1{a} = c
{"ft_lang_label":"__label__en","ft_lang_prob":0.8646643,"math_prob":0.78219074,"size":1231,"snap":"2022-27-2022-33","text_gpt3_token_len":386,"char_repetition_ratio":0.1401793,"word_repetition_ratio":0.00921659,"special_character_ratio":0.3306255,"punctuation_ratio":0.13765182,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9888313,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-01T14:14:25Z\",\"WARC-Record-ID\":\"<urn:uuid:d5557071-ae84-4da4-a8e2-7d03866647b6>\",\"Content-Length\":\"6726\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7742327c-928d-4feb-86d4-a87d1fa96ae0>\",\"WARC-Concurrent-To\":\"<urn:uuid:56b06cb3-85b4-457e-a05a-60a8cc8a4525>\",\"WARC-IP-Address\":\"208.94.116.166\",\"WARC-Target-URI\":\"https://www.lemoda.net/perl/hash-ref-or-copy/index.html\",\"WARC-Payload-Digest\":\"sha1:LKHKY5PJFV7B4TINBFAXO35UD36OTWC7\",\"WARC-Block-Digest\":\"sha1:GPOBBXWH4OMIYSIBKXBLEIYMCBOFPBY3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103941562.52_warc_CC-MAIN-20220701125452-20220701155452-00753.warc.gz\"}"}