in reply to What does 'next if $hash{$elem}++;' mean?

  1. If a key doesn't exist in a hashref before it's used, it's created for you automatically. This is called autovivification.
  2. The postfix increment operator (++) will increment the value of the thing it's after, then return the old value.
  3. next will skip to the next iteration of the loop.

So, this code will skip to the next iteration of the loop if it's already seen that element. Just as if you'd read the code out loud. :-)


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re: What does 'next if $hash{$elem}++;' mean?

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.