Of course, the hash key may be any expression, not just the literal
strings and simple scalar variables that we're showing here:
$foo = "bar";
print $family_name{ $foo . "ney" }; # prints "rubble"
When you store something into an existing hash element, that
overwrites the previous value:
$family_name{"fred"} = "astaire"; # gives new value to existing element
$bedrock = $family_name{"fred"}; # gets "astaire"; old value is lost
That's analogous to what happens with arrays and scalars; if
you store something new into $pebbles[17] or
$dino, the old value is replaced. If you store
something new into $family_name{"fred"}, the old
value is replaced as well.
Hash elements will spring into existence by assignment:
$family_name{"wilma"} = "flintstone"; # adds a new key (and value)
$family_name{"betty"} .= $family_name{"barney"}; # creates the element if needed
That's also just like what happens with arrays and scalars; if
you didn't have $pebbles[17] or
$dino before, you will have it after you assign to
it. If you didn't have $family_name{"betty"}
before, you do now.
And accessing outside the hash gives undef:
$granite = $family_name{"larry"}; # No larry here: undef
Once again, this is just like what happens with arrays and scalars;
if there's nothing yet stored in
$pebbles[17] or $dino,
accessing them will yield undef. If there's
nothing yet stored in $family_name{"larry"},
accessing it will yield undef.