CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Ping Script - Perl.exe Crashing


New User

Jul 17, 2014, 9:21 AM

Post #1 of 4 (1077 views)
Ping Script - Perl.exe Crashing Can't Post


I am fairly new to Perl, and want to write a script that regularly pings various locations. Ideally I want to script to run on Windows and Linux PCs. I want to script to be able to run indefinitely (days) until a key press.

The script seems to perfectly until Perl.exe crashes without an error message. It doesn't seem to happen after regular amounts of time either - hours or days.

The script and an example config are attached.

Does anyone have any thoughts.. all help is much appreciated!

(This post was edited by chazzquire on Jul 17, 2014, 9:28 AM)
Attachments: config.xml (0.43 KB) (5.43 KB)

Veteran / Moderator

Jul 17, 2014, 10:10 AM

Post #2 of 4 (1068 views)
Re: [chazzquire] Ping Script - Perl.exe Crashing [In reply to] Can't Post

Are you sure perl is crashing? I'd think your script is what is crashing.

Since you specifically stated perl.exe, are you saying that it's crashing on Windows, but not on Linux?

Is that the full script or is it a scaled down version of the actual script you're running?

You've got too much code duplication. You should refactor the script to remove as much of that duplication as possible.

Your logging could be greatly improved if you would use one of the good logging modules on cpan, such as Log::Log4perl.

New User

Jul 17, 2014, 11:11 AM

Post #3 of 4 (1063 views)
Re: [FishMonger] Ping Script - Perl.exe Crashing [In reply to] Can't Post

Sorry.. yes I agree it's the script thats crashing. What I meant was it crashed with a Perl.exe has stopped working error message (in Windows) rather than a Perl error.

It was a part of a bigger script (with multiple functions being called), but to get to the route cause I've removed everything else.

I understand that my code isn't great.. could you give me an example of something I could refactor?


Veteran / Moderator

Jul 17, 2014, 4:15 PM

Post #4 of 4 (1050 views)
Re: [chazzquire] Ping Script - Perl.exe Crashing [In reply to] Can't Post

I don't have time to rewrite your code, but I can give you some suggestions.

Most of the code in each of those 3 subs is exactly the same and only a few lines in each are specific to the given task. Extract that common code and put it into a new sub lets call it test() which will act as a wrapper for those test subs. Instead of calling TCPPingTest() you call the wrapper sub and pass it the type of test to preform and it will call the appropriate test sub.

Making this script platform independent will be problematic if you are using threads. Perl is not thread safe on Windows. Newer versions have better thread support, but they are still problematic. The code you posted isn't making use of threads other than loading the pragmas, but if your running code does, then that could be the cause of the crashes.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives