http://qs1969.pair.com?node_id=11140217


in reply to Get unique fields from file

I had this piece of code used somewhere but I hardly can understand it:

Breaking that down into stages:-

My preference is to limit the scope of %seen to a do block so that it isn't left lying around.

johngg@abouriou:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' say q{}; my @arr = qw{ a b c d c e f a b b g d }; my @uniq = do { my %seen; grep { not $seen{ $_ } ++ } @arr; }; say qq{@uniq};' a b c d e f g

I hope this makes the process clearer for you but ask further if something is still not clear.

Cheers,

JohnGG