?
Solved

Perl Script Keeps Closing

Posted on 2011-02-17
2
Medium Priority
?
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
group0 earned 2000 total points
ID: 34919537
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
ID: 34919980
Commenting out that line worked perfectly.  I guess I need to know more Perl before doing the other tasks you mention.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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