in reply to errors
So what you should do is test for the defined-ness of the value:
By the way, you really don't need to build the @dupes array in the above example; you have all the information you need in your hash. The duplicate lines are the keys in the hash where the value is greater than 1:while (defined($_ = <>) and $_ ne "quit\n") { ...
Just something to think about.my @dupes = grep $lines{$_} > 1, keys %lines;
And by the way, here's a one-liner that does basically the same thing:
I'm sure someone else could shorten this. :)% perl -ne 'END { print grep $s{$_}>1, keys %s } last if $_ eq "qu +it\n"; $s{$_}++' file
|
|---|