If you’re looping over the hash in the same scope it was declared in, and only that scope ever looks at it, then each is fine. ...provided you don't modify the scoped hash while you're looping, don't nest loops...

I mentioned previously that we were aiming to organize a second free public talk in Oslo. And I can now confirm that, in addition to my talk next Wednesday night, I will now also be speaking at the University of Oslo, on Friday March…

A thousand years ago, Viking raiders poured out of the frozen North to terrify and oppress my poor Celtic ancestors. But now it's our turn! That's right: once again, I'm returning to Oslo to spread mayhem, fear, and Perl (and not necessarily in that order!)

Ross asked: how will Method::Signatures or similar extension modules work with the 5.19 proposal? For the moment, M::S and the other modules will remain independent of the new signatures feature of 5.19+. They will certainly continue to work correctly. You...

I'm just putting the final touches on another speaking tour through Europe (so expect more posts as I nail down destinations and events). I seem to be working backwards though, because the very last event of the visit—in Switzerland in early April—is already solid.

So, for the first time in several years, I'm travelling though North America on a speaking tour. It's great to be back here, and I'm very much looking forward to the various Perl Monger events we have planned. I dearly wish I could get to more places around the continent, but these days I'm…

I'm delighted to announce that, once again, I'll be teaching in Zurich...next month. My good friends at Oetiker+Partner and the amazing team at Eidgenössische Technische Hochschule Zürich ("ETHZ" to its friends) have organized

@Jerome: @Nick nailed it. This is an enterprise conference, which means that employers are almost always picking up the tab. And the prices for this conference are actually fairly modest (for that universe). In particular, the cost to attend just...

Life can be strange. Not counting endless transits through Heathrow (presumably some horrid form of karmic justice for a particular wicked former life), I have visited London only twice in the past decade. And offered not a single public class there in all that time.

For reasons I don't fully understand, I don't get the chance to give classes very often in my own country. And even less often do I get to give public classes. I'd certainly like to do so more frequently, but the opportunities just don't seem to arise.

Comment Threads

I only hit a problem with each recently (see http://www.martin-evans.me.uk/node/159). Using a hash in list context will use the iterator internally so simply assigning the hash you are iterating over to another hash will cause an infinite loop.

I now never use each. Even if you find the narrow safe cases someone else can come along and easily break your code.

I've also seen situations where each was called in a loop that short-circuits:

while( my ($key, $val) = each %hash ) {
last if $key =~ /foo/;
}

Then later on, each is used again without resetting the internal state, even though the programmer expected to iterate over the entire hash. With a hash stored globally (yes, this is bad in itself, but it happens) in a persistent environment like mod_perl, this can even happen across different requests in the same process.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community.
Written in Perl and offering the modern features you’ve come to
expect in blog platforms, the site is run by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.