in reply to multiple keys hash with array as a value - loop
Try to post runnable code like the following:
I used grep so the "value 2" might be located anywhere in the array.#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; 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'], } ); for my $connection (keys %h) { foreach my $userid (keys %{ $h{$connection} }) { my @ar = @{ $h{$connection}{$userid} }; if (lc $userid eq 'username1') { say "@ar" if grep /value 2/i, @ar; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: multiple keys hash with array as a value - loop
by grandagent (Novice) on Dec 08, 2021 at 20:23 UTC |