Solved

Perl Script Keeps Closing

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Error - Add Failed 12 93
Modify a small python script 19 116
Query group by data in SQL Server - cursor? 3 48
ejb entity bean example 2 15
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

860 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