in reply to keys(%hash) not in scalar context in printf
When you are doing this
my $keys = keys(%r) ;
which is basically this,
my $keys = @keys;
When you are doing the scalar assignment perl can figure out what value you are looking for and assign it to the scalar. Since the default behavior is normally to get the size of the array that is why you get the number of elements in the array.
Your problem is that printf does not implicitly identify keys(%r) to be an array conversion, in large part because an array is a acceptable parameter for printf. Take this example.
printf "Number 1: %d\nNumber 2:%d\nNumber 3:%d\n", values(%r);
If you want force the scalar you should use the scalar function to get what you want.
printf "No of keys=%d\n", scalar keys(%r);
|
|---|