Oh, I was wrong on that part!! Thank you!! But when I changed that into '>', still nothing was written on the file 'DURING PROGRAM RUNNING TIME'. So I was confused...and I found that Perl writes the contents to the file 'WHEN IT CLOSED THE FILE'. So during running time, for 4~8 hours, I could not see anything in the file. That's one of the reason why I thought this code was not working. ^^;
–
S.J.Jan 3 '12 at 13:28

1

That's buffering for you. Perl keeps data in a buffer until it's full, then flushes it to the file when the buffer is full, or the file is closed. You can make the buffer flush immediately to the file by using the line: $| = 1; before opening your file.
–
RohaqJan 4 '12 at 17:55

@Rohaq Thank you so much!! I learned a new thing! ^^
–
S.J.Jan 4 '12 at 18:17

It's looking like read access is unnecessary; i'm not seeing where the script reads the file at all. Plain old write (>) or append (>>) should do.
–
cHaoJan 2 '12 at 5:36

Ah, I assumed he might have been using the read access for a reason. Yep, write/append access is probably best then.
–
RohaqJan 2 '12 at 5:39

Oh, I was wrong on that part!! Thank you!! But when I changed that into '>', still nothing was written on the file 'DURING PROGRAM RUNNING TIME'. So I was confused...and I found that Perl writes the contents to the file 'WHEN IT CLOSED THE FILE'. So during running time, for 4~8 hours, I could not see anything in the file. That's one of the reason why I thought this code was not working. ^^;
–
S.J.Jan 3 '12 at 13:30

Since you posted the same comment under my solution :): That's buffering for you. Perl keeps data in a buffer until it's full, then flushes it to the file when the buffer is full, or the file is closed. You can make the buffer flush immediately to the file by using the line: $| = 1; before opening your file.
–
RohaqJan 4 '12 at 17:57

While this code isn't any shorter, or clearer, it would be very easy to add another tag to compare against. So it isn't really better, as less repetitive.
I would like to point out that $_ =~ /.../ is better written as /.../.

Perhaps the worst part of the code is that you define almost all of you variables up-front.

This means that you are practically using global variables. While some of these appear to need to be defined there, some of them don't, and therefore shouldn't be defined there. You should really be defining your variables at the point you need them, or at least at the beginning of the block where you need them.

Sincerely thank you very much for your kind comments. As you might guessed already, I've been using C for several years and started using Perl just 4 month ago. Your comments will help me a lot. Thank you so much and Happy New Year!!! ^^
–
S.J.Jan 3 '12 at 13:27

@user1125721 I was worried that I might have come off overly critical. I'm glad that at least you don't think so.
–
Brad GilbertJan 3 '12 at 16:39