Solved

Perl Script Keeps Closing

Posted on 2011-02-17
2
353 Views
Last Modified: 2012-05-11
I am a PERL novice but have this example script that connects to a news service and downloads XML data through a TCP port.  The script is supposed to run continuously monitoring the xml as it comes in throughout the day.  But currently after each bit of xml comes across the script stops and kicks me back out to a command prompt.  (I'm using activeperl on Windows but I doubt that matters).  How do I get it to run continuously?  Below is the end of the script.  I'll post the entire 75 line file if you want but I imagine the problem is somewhere in these few lines.  I tried commenting out the last three lines but that had no effect.
while ($socket)
{
      ## receive each line of content
      $socket->recv($data,100,0);
      print $data;
      print LOG $data;
      last if $data =~ m,</message>,i;
}

close LOG;
close $socket;
exit 0;

Open in new window

0
Comment
Question by:Thread7
2 Comments
 
LVL 5

Accepted Solution

by:
group0 earned 500 total points
Comment Utility
Line 7 is breaking out of the while loop as soon as it hits a </message> tag and falling through to lines that terminate the script.

Also, since it's a TCP connection, you need to handle the possibility that the remote end closes the connection.  You can have a while(1) loop that periodically connects to the service, fetches the XML, closes the connection and then sleeps for a bit before beginning the next iteration.  However, if you need to make sure you're not logging duplicate data, you'll need to do some processing on the returned data and somehow keep track of messages that have already been received.
0
 
LVL 1

Author Closing Comment

by:Thread7
Comment Utility
Commenting out that line worked perfectly.  I guess I need to know more Perl before doing the other tasks you mention.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now