Hello Perl Monks I have a text file as
[17/May/2005:18:15:59 -0700]sdjhsj USERID=t70xvcy; jdhdh JSESSIONID=00 +00RDnYTABcRWOx0UN2Zq--sZB:10f408hdg [17/May/2005:18:15:59 -0700]sdjhsj USERID=t70xvcy; jdhdh JSESSIONID=00 +00RDnYTABcRWOx0UN2Zq--sZB:10f408hdg [17/May/2005:18:15:59 -0700]sdjhsj USERID=t70xvcy; jdhdh JSESSIONID=00 +00RDnYTABcRWOx0UN2Zq--sZB:10f408g13
I have the code as
my $FileName = "test.txt"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(tim +e); open ACCESS,"< $FileName" || die "Can't open the file...."; my %User_Lst; while (<ACCESS>) { if (/:(..):(..):(..).*USERID=([a-z0-9].+; ).*JSESSIONID=([a-z0-9].+)/ +){ $l_hr=$1; $l_min=$2; $l_sec=$3; $UserID=$4; $session=$5; $UserID=~s/;.*//g; $session=~s/.*://g; $User_Lst{$UserID}=join(":",$l_hr,$l_min,$l_sec); # $User_Lst{$sessionid}=$session; } } my $l_Counter=0; #while ( (($UserID,$sessionid $TStamp) = each (%User_Lst)) and (($sess +ionid) = each (%Session_Lst))) { while ( ($UserID, $TStamp) = each (%User_Lst)) { print sprintf("Server Name :%s,\t User Name: %s ,\t Time:%s \n", +$sessionid, $UserID, $TStamp); $l_Counter++; } close ACCESS;
Now the problem I am facing is that how do I push session on to the hash so that I can extract it later in order to populate the result. Appreciate your help.

In reply to Hash problem by Nesh

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.