An easier to understand (for a beginner ) example might be:
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Data::Dumper;
my @array = ( 1, 2, 3, 4, 5, 1, 2, 3, 99 );
my %seen = ();
my @unique_elements = ();
foreach my $element (@array)
{
push (@unique_elements, $element) unless
$seen{$element}++;
}
print Dumper @array;
print Dumper @unique_elements;
the %seen hash relies on the autovivification feature of perl to initialize $seen{$element} when its seen. $seen{element}++ is just saying that its seen more than once... Doing a print Dumper %seen may help you.
But as the others have said - reading the documentation is key. Data::Dumper is a great module for viewing data structures. Also diagnostics can also be helpful. Good luck.
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
--Ralph Waldo Emerson
|