StackedHash Perl program help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting StackedHash Perl program help
# 1  
Old 06-11-2008
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 :-( 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
# 2  
Old 06-11-2008
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.
# 3  
Old 06-11-2008
Problem is resolved

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies

2. Shell Programming and Scripting

Perl program

can anyone help me out to write a code by connecting to the sql database and I need to print the list of tables present in the databse. any ideas please. (1 Reply)
Discussion started by: ramkumar15
1 Replies

3. Shell Programming and Scripting

awk program in perl

Hi All, I have an AWK code snippet which I want to use in Perl. How can I achieve the same thing in perl? Here I am searching for a pattern in a file and from that matching line, I am extracting the 3rd column value and storing it in a variable which I later on use this value in a if condition. ... (2 Replies)
Discussion started by: sanzee007
2 Replies

4. Shell Programming and Scripting

getting no output with my perl program

hi, i have posted the same kind of the question in some other forum of the same site. but realized that it is supposed to be here so i am reposting it .this is the perl script written to check for particular pattern. my file 1 would look like this hwk:678:9878:asd:09: abc cfgb 12 nmjk ......... (3 Replies)
Discussion started by: anurupa777
3 Replies

5. Shell Programming and Scripting

Help regarding a Perl Program

I want to traverse a durectory for a particular file. Situataion is like this. Path is ABC/a/c/g. it has around 100 folders in it. Search a directory which has word "*latest*" in its path. and then from the latest go through z/x/c to file final.html. In total, i want it to go through... (4 Replies)
Discussion started by: hemasid
4 Replies

6. Programming

Perl program

Hi I am new to perl, i need to write a program to convert horizontal words to vertical eg: cat, dog, cow,.....(text file) this should be written as 1.cat 2.dog like this. can u pls help me to work out.. (4 Replies)
Discussion started by: nitha
4 Replies

7. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

8. Shell Programming and Scripting

perl program

could i get any help with how to link this program together. i dont know what to put where the X's are print `flush`; thank(); #print thank header use Getopt::Std; # use declaration with the options function getopts("ld:") or usage() and exit; ... (3 Replies)
Discussion started by: livewire06
3 Replies

9. Shell Programming and Scripting

perl program

I wish to write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted order by the file name. • By default, the program displays only file names. • By default, the program lists the files in the current directory. • The program must provide the... (2 Replies)
Discussion started by: livewire06
2 Replies

10. Linux

an error in perl program

Hi I am having a file with 243 lines.. The file format s given below eg P25787 hsa03050 1 P20618 hsa03050 1 P25786 hsa03050 1 P49721 hsa03050 1 P54132 hsa03440 1 Q13472 hsa03470 1 Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 ... (0 Replies)
Discussion started by: binnybio
0 Replies
Login or Register to Ask a Question