Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: multiple keys hash with array as a value - loop

by LanX (Saint)
on Dec 08, 2021 at 17:03 UTC ( [id://11139476]=note: print w/replies, xml ) Need Help??


in reply to multiple keys hash with array as a value - loop

borrowing the data from choroba

use v5.12; use warnings; my $h = { 'connection-id0' => { username1 => ['value 1', 'value 2'], username2 => [ 'value5' ], }, 'connection-id1' => { username1 => ['value 2', 'value 3'], }, 'connection-id2' => { username1 => ['value 3', 'value 4'], } }; while ( my ( $con, $h_users) = each %$h ){ while ( my ($user, $a_vals) = each %$h_users ) { my $val = $a_vals->[1] // ""; say "Found $con -> $user -> $val" if $val =~ /value/; } }
OUTPUT:
Found connection-id2 -> username1 -> value 4 Found connection-id1 -> username1 -> value 3 Found connection-id0 -> username1 -> value 2

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139476]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (8)
As of 2024-04-18 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found