title: Push into end of hash in Perl
body: <p>So what I am trying to do with the following code is push a string, let's say "this string" onto the end of each key in a hash.  I'm completely stumped on how to do this.  Here's my code:</p>
  
  <pre><code>use warnings;
  use strict;
  use File::Find;
  
  my @name;
  my $filename;
  my $line;
  my @severity = ();
  my @files;
  my @info = ();
  my $key;
  my %hoa;
  my $xmlfile;
  my $comment;
  my @comments;
  
  open( OUTPUT, "&gt; $ARGV[0]" );
  my $dir = 'c:/programs/TEST/Test';
  
  while ( defined( $input = glob( $dir . "\\*.txt" ) ) ) {
      open( INPUT, "&lt; $input" );
  
      while (&lt;INPUT&gt;) {
          chomp;
  
          if (/File/) {
              my @line = split /:/;
              $key = $line[1];
              push @{ $hoa{$key} }, "Filename\n";
          }
  
          if ( /XML/ ... /File/ ) {
              $xmlfile = $1;
              push @{ $hoa{$key} }, "XML file is $xmlfile\n";
  
          }
          if (/Important/) {
              push @{ $hoa{$key} }, "Severity is $_\n";
          }
          if (/^\D/) {
              next if /Important/;
              push @{ $hoa{$key} }, "Given comment is $_\n";
          }
          push @{ $hoa{$key} }, "this string\n";
      }
  
  }
  
  foreach my $k ( keys %hoa ) {
      my @list = @{ $hoa{$k} };
      foreach my $l (@list) {
          print OUTPUT $l, "\n";
      }
  }
  
  }
  close INPUT;
  close OUTPUT;
  </code></pre>
  
  <p>Where I have "this string" is where I was trying to push that string onto the end of the array.  However, what ended up happening was that it ended up printing "this string" three times, and not at the end of every key like I wanted.  When I tried to put it outside the while() loop, it said that the value of $key was not initialized.  So please, any help?  And if you need any clarification on what I'm asking, just let me know.  Thank you!</p>