Given that $struct is a data structure that can be either a hash or an array reference, I have some code that looks like this:
for (ref($struct) eq "HASH" ? values %$struct : values @$struct) {
# process $_
...
}
I would like to use the new functionality of the values function (to accept a reference to an unblessed hash or array) to write this instead, which works in my 5.14.2 release:
for (values $struct) {
# process $_
...
}
So much prettier!
But the documentation for values says that this feature is “highly experimental.” It has been around for several releases now (5.12 through 5.16.0 as far as I can tell). Does anyone know what the status is? How is the experiment working out?
It’s marked as experimental because it’s a controversial change. It’s controversial because it doesn’t work on all references to hashes.* No new has been discovered since the feature was introduced, but I don’t think anyone expected any new problems to be discovered.
* —
values($hash)can fail wherevalues(%$hash)would succeed. Your original code has exactly the same problem, so this “limitation” ofvaluesisn’t a problem for you.