How to keep track of counter dynamically in perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to keep track of counter dynamically in perl?
# 1  
Old 06-30-2010
How to keep track of counter dynamically in perl?

Hi,

I have to perform the two things;

a) Have to check the previous counter value in the file.
b) After some processess are runned again i have to check the same counter value in the same file.

Here is the file contents.
Code:
#File contents of file.txt
CounterValue: 0

Here is the code.
Code:
open(FH,"file.txt");
@lines=<FH>;
foreach($lines)
{
	if($_=~/CounterValue:\s+(\d+)/)
	{
		print "\nCounter value is: $1 \n";
		$previous=$1;
		last;
	}
	
}
print "\nPrevious value of counter: $previous \n";

Some other process will run and the file.txt gets changed to the new value.

Now contents of file are:
Code:
CounterValue: 1

The Output should be:

Code:
The previous value of counter: 0
The latest value of counter: 1

I am having the problem here because when the program is run the file.txt contents is replaced again the previous and new value will be 1.

How can i check the previous and new value of counter in the file?

Should i use the same code for new and previous values?

How do i get the above output?

Regards
vanitha

Last edited by Franklin52; 06-30-2010 at 08:38 AM.. Reason: correcting code tags
# 2  
Old 06-30-2010
Seems like a pretty straightforward case. You have the script X to capture the "Counter Value" from the file.

1) Run the script X and capture the (old) "Counter Value".
2) Run the processes that update your file.
3) Run the script X again, and capture the (new) "Counter Value".

tyler_durden
# 3  
Old 07-01-2010
Quote:
Originally Posted by durden_tyler
Seems like a pretty straightforward case. You have the script X to capture the "Counter Value" from the file.

1) Run the script X and capture the (old) "Counter Value".
2) Run the processes that update your file.
3) Run the script X again, and capture the (new) "Counter Value".

tyler_durden
Hi,

Thanks for your mail.

The code above posted can i use that.

But the file when reopen is giving new as well as old value same.

Can you give an example?

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to track the opened tags in xml using perl?

Hi, I have an xml file like this: I am using xml::dom also and libxml. <Nodes> <Node> <NodeName>MainContent</NodeName> <data>1.csv</data> <Node> <NodeName>Status</NodeName> <IsWrapper/> ... (3 Replies)
Discussion started by: vanitham
3 Replies

2. Shell Programming and Scripting

How to dynamically create user name in perl and move the files?

Hi, I have two problems in which i have stuck up. a) To move the files and copy back. b) To create user dynamically. Question 1: I have to move the files to some other directory and copy it when all the process is done. I have the code like this: $file = "/home/data/file1.txt";... (2 Replies)
Discussion started by: vanitham
2 Replies

3. Shell Programming and Scripting

How to create hash dynamically in perl?

Hi, I have one file name file.txt It has the following contents: #File Contents StartTime,EndTime,COUNTER1,COUNTER2,COUNTER3 12:13,12:14,0,1,0 The output should be like this: StartTime: 12:13 ENDTIME: 12:14 (2 Replies)
Discussion started by: vanitham
2 Replies

4. UNIX for Dummies Questions & Answers

Track user

Hi, i suddenly realized that a directory is deleted unfortunately there are many user have pervilages on this directory is there a way to track the user who delete this directory or atleast from now can i enable something so that i can track from now I think there is way from... (2 Replies)
Discussion started by: crackgeek
2 Replies

5. Shell Programming and Scripting

keep track of every user

dear all , I m new to shell programming and I need your help. Actually i want to keep track of all the commands executed in a bash prompt of users , very much in same manner as it is displayed when we run "history" command. now the users are smart enough as they delete their history by... (6 Replies)
Discussion started by: xander
6 Replies

6. UNIX for Dummies Questions & Answers

Possible to track FTP user last login? Last and Finger don't track them.

Like the topic says, does anyone know if it is possible to check to see when an FTP only user has logged in? Because the shell is /bin/false and they are only using FTP to access the system doing a "finger" or "last" it says they have never logged in. Is there a way to see when ftp users log in... (1 Reply)
Discussion started by: LordJezo
1 Replies

7. Shell Programming and Scripting

How to set dynamically keys names in perl %hash

hello I have loop , in this loop im picking names , this names I want to be keys in %hash but I don't know how to set in every loop entertain different key in the %hash (1 Reply)
Discussion started by: umen
1 Replies

8. UNIX for Advanced & Expert Users

Track changes in files

All, Is there any command or method by which we can track changes in a file in Unix (Something similar to track changes in a word document). I know there is CVS which is used to store code changes and track changes in the code. But other than CVS any way to find out changes done in a file... (1 Reply)
Discussion started by: rahulrathod
1 Replies

9. HP-UX

9-track dinosaur

We just went from HP-UX 10.20 to 11.00. All the bugs are out, except for a small detail...the old 9-track isn't working. We receive large amounts of data on reel-to-reel so I kinda need it fixed. In the meantime, I'm trying to see if they can send me a DAT tape instead. I'm pretty sure the drive... (8 Replies)
Discussion started by: ncmurf00
8 Replies
Login or Register to Ask a Question