in reply to Re^2: populate hash tab delimited
in thread populate hash tab delimited

Sort of, yes. Except for a couple of details :)

First, by looping over the hash inside the while loop, you print out every value several times: once for every line of the input file.

Second, you haven't opened the output file yet, so you'll likely get an error.

The foreach loop itself is almost right, but you'd want to move it outside the while loop:

#!/usr/bin/perl -w use strict; use diagnostics; my %values = (); unless (open (INFILE, "inputHash.txt")){ die "Cant open input.txt: $!" +;} # opens the file read only while (<INFILE>){ chomp; next unless (/\t/); my ($key, $value ) = split(/\t/, $_, 2); $values{$key}=$value; } close (INFILE); #close input file unless (open (OUTPUT, ">popHash.txt")){die "Cant open popHash.txt: $!" +;} foreach my $key (keys %values) { print OUTPUT "$key $values{$key}\n"; }