Rod Adams wrote:

Does

($k, $v) <== pop %hash;
or
($k, $v) <== %hash.pop;


make sense to anyone except me?

Makes sense to me. Although I would be more inclined to think of pop as returning a pair - but does a pair in list context turn into a list of key, value? If so then the above makes lots of sense.


Since we now have an explicit concept of pairs, one could consider a hash to be nothing but an unordered (but well indexed) list of pairs. So, C<< pop %hash >> would be a lot like C<< each >>, except, of course, that it deletes the pair at the same time.

The only thing people might not be too pleased about is that the order is entirely at the whim of the internal implementation of hashes. I suppose you could say %hash.sort.pop(), but that would probably re-sort every time and that's clearly not desirable. Working on a sorted copy is also not particularly pleasant as memory could be a considerable problem.


If we do that, I'd also want to be able to

push %x, %y;

which would mean something like:

%x{%y.keys} <== %y{%y.keys};

but be much easier to read.

Yes, I'd like that. I find myself wanting to do things like that quite a lot in Perl 5.




Reply via email to