I am creating a hash of hashes and trying to search or do pattern matching.
Hash is
$hash{$var1}{$var2}{$var3}=$value; #where $var1 =1_1 : $var2 =2_1; $var3 =3,4;
and i am trying to do a pattern matching with key var3
here $var4 can change values
for (sort keys %{$hash{'1'}{$var4}}) { # var4=2_1 : can also be 2_2 and so on
if ($_ =~ m/3,.*/) { # here
$new = $_; # here new should get the value 3,4
}
}
The problem I am stuck with is that unless I do the following
for (sort keys %{$hash{'1'}{'2'}})
I cannot sort the keys ; In short cannot replace 2 with a variable.
Have you tried using a nested loop? You’ll need something like this: sort the $var4 keys before going deeper down to access the values you need.