Greetings perl monks, I couldn't find an answer to my question, so hoping I can get some help:
I have some output that looks like: afp:usersArray:_array_index:0:serviceType = "afp" afp:usersArray:_array_index:0:ipAddress = "1.1.1.1" afp:usersArray:_array_index:0:sessionID = 235 afp:usersArray:_array_index:0:loginElapsedTime = 2796 afp:usersArray:_array_index:0:disconnectID = 0 afp:usersArray:_array_index:0:name = "admin" afp:usersArray:_array_index:0:flags = 1 afp:usersArray:_array_index:1:serviceType = "afp" afp:usersArray:_array_index:1:ipAddress = "1.1.1.1" afp:usersArray:_array_index:1:sessionID = 244 afp:usersArray:_array_index:1:loginElapsedTime = 2286 afp:usersArray:_array_index:1:disconnectID = 0 afp:usersArray:_array_index:1:name = "admin" afp:usersArray:_array_index:1:flags = 1 afp:timeStamp = "2011-03-17 16:45:37 -0700"
The goal is to get a username, and sessionid. Also need to associate this with its array index. Here is the code:
#-Code getList(); for (keys %uhash){ print "Final: ArrayNum:$_ and SessionName: $uhash{$_}->{sessionName} + SessionId:$uhash{$_}->{sessionId}\n"; } #-Subs sub getList { open FH,"output"; while (<FH>){ if ($flag{debug}){ print "DEBUG: OUTPUT: $_\n"; } if (/.*array_index:(\d+):serviceType.*/){ $arrayNum = $1; if ($flag{debug}){ print "DEBUG:ArrayNum: $1\n"; } } unless(!$arrayNum){ if (/.*array_index:$arrayNum:sessionID = (\d+)/){ $sessionId = "$1"; $uhash{$arrayNum}->{sessionId} = $sessionId; if ($flag{debug}){ print "DEBUG:SessionId: $sessionId\n"; } } if (/.*array_index:$arrayNum:name = "(\w+)"/){ $sessionName = "$1"; $uhash{$arrayNum}->{sessionName} = $sessionName; if ($flag{debug}){ print "DEBUG:SessionName: $sessionName\n"; } } } } }
Output I get is:
Final: ArrayNum:1 and SessionName: admin SessionId:244
As you can see I am missing array index 0 data. Any help is much appreciated. I need to find a way to run multiple regex against a single file. Thank you in advance!

In reply to while loop and multiple regex by frank_2k4

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.