read through the file "$file"
when a starting session is found
open the file "$file" again, as file2
read through file2 until the end of the session is found
####
my %session_start;
my %session_end;
while( ) {
if( /$pattern/ ) {
# Session starts here
my $started_session= $1; # actually, you do the counting of parentheses
my $session_start_time= $2; # actually, you do the counting of parentheses
if( ! $session_start{ $started_session }) {
# That session really is new
$session_start{ $started_session }= $session_start_time;
} else {
# That session should be new but we already know it
warn "Line $.: Session '$started_session' already started at $session_start{ $started_session }, but also (re)starts at $session_start_time. See [$_]";
};
} elsif( /(\d+-\d+-\d+ \d+:\d+:\d+).*session:(\S{32})/)
my $session_end= $1; # actually, you do the counting of parentheses
my $ended_session= $2; # actually, you do the counting of parentheses
# Session was seen here, or might end here
if( ! $session_start{ $ended_session }) {
# That session is unknown?!really is new
warn "Line $.: Session '$ended_session' never started, but ends at $session_end. See [$_]";
} else {
# That session was seen here
$session_end{ $ended_session }= $session_end;
};
}
};
####
for my $session (sort keys %session_start) {
print "Session: $session - $session_start{ $session } - $session_end{ $session }\n";
};