in reply to Question about hashes

The code you have is correct, although fglock gives you a simpler and more idiomatic way to do it.
#!/usr/bin/perl -w use strict; my %h = (1 => "one", 2 => "two"); %h = (%h, 3, "three"); %h = (%h, 4, "four"); print "h is:\n",printhash(%h); sub printhash { my $i = 0; join("",map { $_.($i++%2?"\n":" => ") } @_); }
produces
h is:
1 => one
2 => two
3 => three
4 => four

Consider using debugging information to see if your error is elsewhere---for example, printing out the contents of $file and $text whenever you add to the hash.