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

Re: Unable to set the recent date from hash of array of hashes.

by tybalt89 (Monsignor)
on Mar 16, 2021 at 19:15 UTC ( [id://11129789]=note: print w/replies, xml ) Need Help??


in reply to Unable to set the recent date from hash of array of hashes.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129741 use warnings; use List::Util qw( maxstr ); my %hash = ( 266000003 => { "Network1" => ["NA"], "Network1 ENV" => ["2021-03-08T13:34:59.000Z"], }, 566000003 => { "Network1" => ["NA", "NA", "NA", "NA", "NA", "NA +", "NA", "NA", "NA"], "Network1 ENV" => [ "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", "2020-09-09T18:36:50.000Z", ], "NETWORK2" => [ "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", "2021-03-10T18:15:54.000Z", ], }, 900000001 => { NETWORK2 => [ "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", "2020-12-17T19:36:21.000Z", ], }, ); #use Data::Dump 'dd'; dd \%hash; my %best; for my $id (keys %hash) { for my $net ( keys %{ $hash{$id} } ) { for ( @{ $hash{$id}{$net} } ) { /T/ and $best{$id} = maxstr "$_,$net", ($best{$id} // ''); } } } printf "SSO ID: %s, Mfa Cat : %s , Valid: %s\n", $_, reverse split /,/ +, $best{$_} for sort keys %best;

Outputs:

SSO ID: 266000003, Mfa Cat : Network1 ENV , Valid: 2021-03-08T13:34:5 +9.000Z SSO ID: 566000003, Mfa Cat : NETWORK2 , Valid: 2021-03-10T18:15:54.000 +Z SSO ID: 900000001, Mfa Cat : NETWORK2 , Valid: 2020-12-17T19:36:21.000 +Z

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2024-04-19 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found