Hi All,

As suggested, I tried to work on myself and have come up with following code, so far I have implemented the following steps :

1. Define two hashes: %users and %searches

2. Process the logfile line by line. For each line, use a regex to see if it matches the BIND or RESULT form, and extract the relevant fields ($conn, $uid, etc.) if it does. Also:

2a.If it is a BIND line: Add an entry to the %users hash, with $conn as the key and $uid as the value.

2b. If it is a RESULT line: Add relevant information (about the timestamp of the search) to the value of the %searches entry that belongs to the key $conn.

At this point, I am not sure how to compare the three occurrence. Please help me.

#!/usr/bin/perl #use warnings; #use strict; use 5.010; open(IN, "logs.txt") or die "can not open file"; my %users; my %searches; while (<IN>){ if (/BIND/){ my ($conn) = /conn=(\d+)\s/; my ($uid) = /uid=(.*?),/; $users{$conn} .= exists $users{$conn} ? " $uid, " : $uid; print %users; } if (/SRCH=Q/){ my ($conn1) = /conn=(\d+)\s/; my (@line) = split(" ",$_); my $timestamp = "$line[0]\n"; $searches{$conn1} = exists $searches{$conn1} ? " $timestam +p," : $timestamp; print %searches; } }

In reply to Re^4: Pull users with multiple search by johnprince1980
in thread Pull users with multiple search by johnprince1980

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.