Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by LanX (Sage)
on Dec 08, 2021 at 17:03 UTC ( #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? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2023-01-27 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?