Solved

Perl Script Keeps Closing

Posted on 2011-02-17
2
355 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

816 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

10 Experts available now in Live!

Get 1:1 Help Now