in reply to null output on hashes
"You are trying to get a list of items that appears in both file1 and file2, concatenate them together, and disregard the rest".
Tailor as needed.#!/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]++; } }
Of course there are some caveats such as only the last seen value of a key will get used.
Cheers - L~R
|
|---|