Created
August 23, 2012 17:03
-
-
Save smujohnson/3438752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
# Notice that the values are all equal for some of the keys | |
my @stuff = ( | |
{ a => "1", b => "2", c => '4'}, | |
{ a => "1", b => "3", c => '4'}, | |
{ a => "1", b => "2", c => '4'}, | |
{ a => "1", b => "2", c => '4'}, | |
{ a => "1", b => "2", c => '4', d => '2'}, | |
); | |
my %hash_count; | |
foreach my $ref_row (@stuff) { | |
foreach my $key_letter (keys %$ref_row) { | |
$hash_count{$key_letter}{ $ref_row->{$key_letter} }++; | |
} | |
} | |
my @keys_total = keys %hash_count; | |
say "All the keys in \@stuff: @keys_total"; | |
my @keys_equal; | |
foreach my $key_letter (keys %hash_count) { | |
if (keys %{ $hash_count{$key_letter} } == 1) { | |
push @keys_equal, $key_letter; | |
} | |
} | |
say "The keys for which all values are equal: @keys_equal"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks
Indeed.