in reply to Compare array - hash
Here are the results:use strict; my @user = (1,3,5,7,9); my %log = ( 1 => 'today', 2 => 'today', 3 => 'yesterday', 4 => 'last week', 5 => 'now' ); my %result; foreach my $x (@user) { # Save the id ($x) in the result hash, save the location # of data as value, 'both' if $log{$x} exists, user if not $result{$x} = $log{$x} ? 'both' : 'user'; } foreach my $y (keys %log) { # Save the id ($y) in the result hash, save the location # of data as value only if the id does not exist in result # hash yet $result{$y} = 'log' unless $result{$y}; } foreach my $z (sort keys %result) { print "$z: $result{$z}\n"; }
1: both 2: log 3: both 4: log 5: both 7: user 9: user
|
|---|