in reply to Re: creating a new file with unique values
in thread creating a new file with unique values

Why would you want to delay writing the file? If no hash-entry exists yet, you know it can be written anyway...

Also using foreach/keys to loop thru a hash if very inefficient, especially with big hashes; perl has to traverse the entire hash to collect all the keys, and when obtaining the value in the loop body, it has to look-up the key in the hash again.

The preferred method would be to use a while/each loop. Your code would then look like:

while(my ($i,$count) = each %input) { print OUT "$i\n" unless $count>1; }

Using the while/each construct would also be a lot cleaner if the hash happened to be something like a tied database query result hash, if said hash supported database row cursors... But that actually has nothing to do with the topic... :)

Happy coding, G.