Last active
April 18, 2017 22:17
-
-
Save natemccurdy/a6b50deb2ebb224aa568197e5bde56d9 to your computer and use it in GitHub Desktop.
Find the name of a key whose attribute matches some string
This file contains hidden or 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
$service_accounts = { | |
'larry' => { | |
gid => '1111', | |
tag => 'group_a', | |
}, | |
'moe' => { | |
gid => '2222', | |
tag => 'group_b', | |
}, | |
'curly' => { | |
gid => '3333', | |
tag => 'group_c', | |
}, | |
} | |
$group_b_svc_account = $service_accounts.filter |$name, $attr| { | |
$attr['tag'] == 'group_b' | |
}.keys[0] | |
notice($group_b_svc_account) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This also works, but is arguably harder to read...