in reply to null output on hashes

tux242,
As I explained in the CB, I understand how frustrating it can be just getting started. If you can put in clear and concise terms what you are trying to accomplish, we will be much more able to help you. What I discerned from the CB is this:

"You are trying to get a list of items that appears in both file1 and file2, concatenate them together, and disregard the rest".

#!/usr/bin/perl -w use strict; my %data; my @files = qw(file1.dat file2.dat); for my $file ( @files ) { parse_file( $file, \%data ); } for my $key ( grep $data{$_}->[1] > 1 , keys %data ) { print join ':' , $key , $data{$key}->[0]; } sub parse_file { my ($file, $data) = @_; open (INPUT, $file) or die "Unable to open $file : $!"; while ( <INPUT> ) { my ($key, $value) = split /:/ , $_ , 2; $data->{$key}[0] = $value; $data->{$key}[1]++; } }
Tailor as needed.
Explanation:
  • Use a single hash of Arrays (HoA) for any number of files.
  • Each hash key points to an array with two indices
  • The first index (0) is the expected value
  • The second index (1) is how many times this key has been seen
  • Only pull out keys were the second index has been seen more than once

    Of course there are some caveats such as only the last seen value of a key will get used.

  • Cheers - L~R