Perl Style: Use Hashes for the First Time

  • A hash is a good way to keep track of whether you’ve done something before.
  • Embrace the ... unless $seen{$item}++ notation:

        %seen = ();
        foreach $item (genlist()) {
            func($item) unless $seen{$item}++;
        }
    

Forward to Use Hashes of Records, not Parallel Arrays
Back to Use Hashes for Sets
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub