StackedHash Perl program help

Hi guys,

I need a favor from you guys. I am working on perl script which uses StackedHash( Thanks to Riccardo Murri) perl module and am almost there but unable to get it done. I really appriciate your help on this. Here are the details.

thanks
Purna

Requirement:

Find out setting session state connection statements which don't have corresponding Returning WS connections in a given input file

check_test_3_1.pl

#!/usr/bin/perl -n

use Data::StackedHash;
tie %array1, Data::StackedHash;

if (m/(.) \[DEBUG\] \[([^][]+)\] RMSConnectionFactory - Setting session/) {
tied(%array1)->push({$2=>$_});
next;
}
if (m/(.
) \[DEBUG\] \[([^][]+)\] RMSConnectionFactory - Returning WS /) {
if ("$2" ne "" ) {
delete $array1{$2};
}
next;
}

END {
print values %array1;
}

Input file:

2008-06-05 03:29:37,752 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:37,761 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,061 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,069 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,292 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,301 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,442 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,506 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,572 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,579 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,762 [DEBUG] [AQUEDUCT-WebContainer : 2] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,768 [DEBUG] [AQUEDUCT-WebContainer : 2] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:38,961 [DEBUG] [AQUEDUCT-WebContainer : 0] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:38,969 [DEBUG] [AQUEDUCT-WebContainer : 0] RMSConnectionFactory - Returning WS connection.

2008-06-05 03:29:39,292 [DEBUG] [AQUEDUCT-WebContainer : 2] RMSConnectionFactory - Setting session state for connection.

2008-06-05 03:29:39,772 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:39,839 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:40,261 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:40,272 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.

2008-06-05 03:29:40,701 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.

2008-06-05 03:29:41,291 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:41,300 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.
2008-06-05 03:29:41,542 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:41,551 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Returning WS connection.

Expected Output:

2008-06-05 03:29:40,701 [DEBUG] [AQUEDUCT-WebContainer : 1] RMSConnectionFactory - Setting session state for connection.
2008-06-05 03:29:39,292 [DEBUG] [AQUEDUCT-WebContainer : 2] RMSConnectionFactory - Setting session state for connection

What i am getting right now:

Nothing :frowning: program runs successfully but with no output ..

Run command:

perl -w check_test_3_1.pl input.txt

Dependency Perl Modules:

Data::StackedHash - Stack of PERL Hashes - search.cpan.org

turn on warnings;

use warnings;

I am not on a computer that has perl installed so I can't test your code for basic correctness, so first make sure no warnings are getting generated that might alert you to problems with the code or the code logic.

Hi

The first two lines (using StackedHash perl module0 should be there in BEGIN {} block which prevents initializing the array every pass.

Problem is resolved.

thanks for looking at my post.