Solved

Perl Script Keeps Closing

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exe program is not a valid Win 32 application 15 103
Windows Service to Receive TCP Packets 4 117
Export Variables in Perl 3 43
Advice on Xojo as a development tool over VB. 4 31
This is an explanation of a simple data model to help parse a JSON feed
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.
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…
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…

932 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

14 Experts available now in Live!

Get 1:1 Help Now