chandantul has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re:How to check last used date.
by davido (Cardinal) on Mar 12, 2021 at 19:31 UTC

    I think you're asking a little bit the wrong question. Why do you need a module that deals specifically with login date? That's specific enough that you won't find what you're looking for. You have two problems and they're not satisfied by a single module:

    • You need to extract data from a log
    • You need to find the max date (possibly per user)
    So the module you really need is one that can compare dates and tell you the most recent. This has nothing to do specifically with login. You just need to parse your input data for dates, and then use a module to compare them.

    Your data looks like it is in column format. In other words, the login date is in a predictable column: Column 36 (offset +35). And your userid is in a predictable column: Column 1 (offset 0) So use substr or unpack to capture the user and the date. Skip lines that don't match (that have NOT REGISTERED in them). Then use a module such as DateTime to compare the dates, finding the most recent. Let us know what part of that you actually have trouble with so that we can help.


    Dave

      In fact, in this date format, dates can be compared as plain strings, no date parsing is needed.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Thanks for the suggestions. I have the data structure that needs 2 dimentional Hash of arrays. I will need to find out the Specific ID and their respective Netowrk IDs and which was not used and the used one Network ID to be checked with Last used among the usages. Please check my latest data structure . How i can create a 2 dimentional Hash of arrays and extract the unique data? Can you please consider @array1 as the Key @array 3 is the 2nd and @arra3 is the respective values? Please check ID 500000008

      @array1 @array3 @array2 @arra3 900000001 900000001 Network1 Login 900000002 900000002 Network1 2019-11-07T20:31:10.000Z 900000002 900000002 Network1 2021-02-19T13:47:25.000Z 900000002 900000002 Network1 2021-03-10T13:58:50.000Z 900000003 NOT Registered No Network1 NOT Registered 900000004 900000004 Network1 Login 900000005 900000005 Network1 Login 900000006 900000006 Network1 Login2 900000007 900000007 Network1 2021-03-10T17:11:24.000Z 900000007 900000007 Network1 2021-02-18T08:34:58.000Z 900000007 900000007 Network1 2021-01-25T17:19:44.000Z 500000008 500000008 Network1 2021-03-10T17:11:24.000Z 500000008 500000008 Network2 Not Used 500000008 500000008 Network1 2021-03-11T17:12:42.000Z 500000008 500000008 Network3 Not Used 400000008 400000008 Network1 2021-01-25T17:19:36.000Z

        So now you have three problems that you seem to be asking about:

        • How to sort by date, or find the maximum date.
        • How to extract the user ID and date from tabular data.
        • How to insert data into a datastructure

        Which part of the problem are you able to solve yourself, so that we can help with the parts you can't solve? Show us the minimal amount of code you can write to get started on this. Sample input, sample output, code that compiles, etc.


        Dave

Re: How to check last used date.
by tybalt89 (Monsignor) on Mar 12, 2021 at 22:08 UTC
    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129526 use warnings; use List::Util qw( maxstr ); my %last; /^(9\d+).*?(\S+T\S+)/ and $last{$1} = maxstr $last{$1} // '', $2 while <DATA>; use Data::Dump 'dd'; dd \%last; __DATA__ @array1 @array3 @array2 @arra3 900000001 900000001 Network1 Login 900000002 900000002 Network1 2019-11-07T20:31:10.000Z 900000002 900000002 Network1 2021-02-19T13:47:25.000Z 900000002 900000002 Network1 2021-03-10T13:58:50.000Z 900000003 NOT Registered No Network1 NOT Registered 900000004 900000004 Network1 Login 900000005 900000005 Network1 Login 900000006 900000006 Network1 Login2 900000007 900000007 Network1 2021-03-10T17:11:24.000Z 900000007 900000007 Network1 2021-02-18T08:34:58.000Z 900000007 900000007 Network1 2021-01-25T17:19:44.000Z

    Outputs:

    { 900000002 => "2021-03-10T13:58:50.000Z", 900000007 => "2021-03-10T17:11:24.000Z", }