The goal is to get a username, and sessionid. Also need to associate this with its array index. Here is the code: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"
Output I get is:#-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"; } } } } }
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!Final: ArrayNum:1 and SessionName: admin SessionId:244
In reply to while loop and multiple regex by frank_2k4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |