Win has asked for the wisdom of the Perl Monks concerning the following question:
in the code:next if $seen{ $elem }++;
My attempt is:my %hash = map { $_, 1 } @array; # or a hash slice: @hash{ @array } = (); # or a foreach: $hash{$_} = 1 foreach ( @array ); my @unique = keys %hash; my @unique = (); my %seen = (); foreach my $elem ( @array ) { next if $seen{ $elem }++; push @unique, $elem; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What does 'next if $hash{$elem}++;' mean?
by dragonchild (Archbishop) on Feb 17, 2006 at 15:32 UTC | |
| |
Re: What does 'next if $hash{$elem}++;' mean?
by blazar (Canon) on Feb 17, 2006 at 17:52 UTC | |
Re: What does 'next if $hash{$elem}++;' mean?
by radiantmatrix (Parson) on Feb 17, 2006 at 19:24 UTC |