What's throwing you off here is that your hash values aren't the actual values, but rather array references (as shown by the [ ... ]
in your Data::Dumper output) pointing to single-element arrays which contain the actual data. So you need to dereference them and grab the first element from the resulting array:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
my %hash1 = ('5555' => [ '13570' ]);
my %hash2 = ('13570' => [ '[04/Jun/2013:15:06:13' ]);
for (keys %hash1) {
my $first_key = $_;
my $second_key = $hash1{$first_key}[0];
say "$first_key -> $second_key -> $hash2{$second_key}[0]";
}
Output:
5555 -> 13570 -> [04/Jun/2013:15:06:13
Edit: Alternate code to check all values in each %hash1
entry and display all corresponding values for each in %hash2
:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
my %hash1 = ('5555' => [ '13570', '8675309' ]);
my %hash2 = (
'13570' => [ '[04/Jun/2013:15:06:13' ],
8675309 => [ 'Jenny', 'I got your number' ],
);
for (keys %hash1) {
my $first_key = $_;
for my $second_key ( @{$hash1{$first_key}} ) {
if (exists $hash2{$second_key}) {
say "$first_key -> $second_key ->";
say "\t$_" for @{$hash2{$second_key}};
}
}
}
Output:
5555 -> 13570 ->
[04/Jun/2013:15:06:13
5555 -> 8675309 ->
Jenny
I got your number