in reply to Why does this hash remove duplicate lines

$lines{$_}++ counts how many times a line has been seen, but because it is a post-increment, not a pre-increment (see perlop), what the "if not" is checking is the number of times it has been seen before the current time. This number will be 0 the first time only. The "if not" (yes, unless would work instead) is the same as "if 0 == $lines{$_}++".

See also http://perldoc.perl.org/perlfaq4.html#How-can-I-remove-duplicate-elements-from-a-list-or-array%3f

  • Comment on Re: Why does this hash remove duplicate lines