If the group assignments are mutually exclusive (no person is assigned to more than one group ... which doesn't look to be the case, as 'apatnayi' is in groups 2 and 4), rather than loop through each of the groups, it's easier to have the lookup be a mapping of the group assignments:
my %lookup = map { my $grp = $_; map { $_ => $grp } ( @{ $groups{$grp} }; } (keys %groups); # ... and then below ... foreach my $name (@usernames) { $output{$time}{ $lookup{$name} }++; # ... or, if you have users logged in that aren't in a group # $output{$time}{ $lookup{$name} }++ if exists $lookup{$name}; # ... or, to track those users with no groups # $output{$time}{ $lookup{$name} || 'unknown' }++; }
If it's not, then you can have the lookup be to an array of what groups they're in, so you don't have to look through each group every time:
my %lookup = (); foreach my $grp (keys %groups) { push @{$lookup{$_}}, $grp foreach @{$groups{$grp}}; } ... foreach my $name (@usernames) { $output($time){$_}++ foreach @{$lookup{$name}}; }
In reply to Re^2: How to match the each line of of users for a perticular time with predeclared group.
by jhourcle
in thread How to match the each line of of users for a perticular time with predeclared group.
by perladdict
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |