Woaw, impressive :) So concise, yet so clear. Not to mention that it actually works too!
I read up about List::Util::first and I wish I knew about it earlier, that's a hell of an awesome subroutine (in fact the whole module is pretty cool, too).
At first I was a bit puzzled about the
(L::U::f)->[0] thing, but of course - all elements are in fact two elements each, and at this point of the progress we only care about the first. Nifty how you put all that in just one line without becoming too obscure.
So much for flattering around, because there's still one part I don't quite understand. They do it in
Weighted random numbers generator too. What does $pick dropping below zero have to do with anything? How does it work? I tried to figure it out by running the code mentally, but I just don't understand...
Update: also, let it be known it's no homework :) I write Perl just as an hobby. I'm not really into computer science or whatsoever - I mean, I understand something like this can't be hard and if it would've been a homework assignment I would be ashamed I couldn't figure it out by myself :)