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 choroba (Cardinal)
on Dec 08, 2021 at 15:50 UTC ( [id://11139475]=note: print w/replies, xml ) Need Help??


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

The code snippets don't correspond to each other. value 2 doesn't match /update\s*[table\s*]rmdb_dbo./i'. Moreover, the string 'table in the square brackets seems like a meaningful word, but square brackets introduce character classes, so [table\s*] in fact matches a single character a, b, e, l, t, asterisk, or whitespace.

Try to post runnable code like the following:

#!/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; } } }
I used grep so the "value 2" might be located anywhere in the array.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

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
    Thanks for the reply "value1/2" are not the acutal strings those are just placeholders. The string looks like this
    value1="UID=rmdb_dbo;DBN=326474...."
    (UID can have different usernames, I just picked rmdb_dbo as an example but it can also be a personal user like "cb2ayal" for example) value2 can be any SQL string like the below
    "update ..." "insert ..." "delete ..."
    I am insterest in the tables with "rmdb_dbo" so I need to grep for this string

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found