What is the shortest amount of code to modify a hash within a hash in the following instances:
%hash{'a'} = { 1 => one,
2 => two };
(1) Add a new key to the inner hash of ‘a’ (ex: c => 4 in the inner hash of ‘a’)
(2) Changing a value in the inner hash (ex: change the value of 1 to ‘ONE’)
Based on the question, you seem new to perl, so you should look at
perldoc perlopamong others.Your
%hashkeys contain scalar values that are hashrefs. You can dereference using the->operator, eg,$hashref = {foo=>42}; $hashref->{foo}. Similarly you can do the same with the values in the hash:$hash{a}->{1}. When you chain the indexes, though, there’s some syntactic sugar for an implicit->between them, so you can just do$hash{a}{1} = 'ONE'and so on.This question probably also will give you some useful leads.