http://qs321.pair.com?node_id=1015


in reply to Control Statement Exercises

# Reads in lines of text until "quit" is read. # Then prints duplicates, or prints "No duplicates seen." my %lines; # holds lines of text encountered along with a count # of how many times it has been seen my @dups; while ( $_ = <> and $_ ne "quit\n" ) { $lines{$_}++; # increment value. if it dosn't exist yet, initializ +es to 1 if ( $lines{$_} == 2 ) # been seen before so add to dupes list { push @dups, $_; } } if ( @dups ) { print "Here are your duplicate lines:\n\n"; foreach ( @dupes ) { print; } } else { print "No duplicates seen.\n"; }