@vals = values %m;
$x = $vals[ int rand @vals ];
The values operation extracts the values of a map (perl hash) into a perl list we call @vals.
The rand operator generates a random (real) number between 0 and the integer argument. In a scalar context, @vals is the length of the list.
We then truncate the decimal portion with int and use the result as an index into the @vals list.
The rand operator generates a random (real) number between 0 and the integer argument. In a scalar context, @vals is the length of the list.
We then truncate the decimal portion with int and use the result as an index into the @vals list.