Main Content

Perl Socket Programming Examples

Archive - Originally posted on "The Horse's Mouth" - 2008-12-02 20:53:39 - Graham Ellis

It's always a pleasure to run private courses - for when a questions that's a little bit away from the normal comes up, I can take time to provide a full answer and demonstration without fear of loosing delegates from other companies who have no interest. And so it was today - I have two examples, plus an old favourite.

Firstly, my customers told me that they'll be running a number of other programs / commands from within Perl, and wish to use Perl as the "puppeteer" - writing to and reading from those other processes even as they run. Choosing ping as an example program to run from within Perl, opened a demonstration process on a pipe and then read from that pipe. See Source code

Then, I was asked about (and got involved) in socket programming. The first example, with it all in a single program, got a little long ... so I refactored into a structured program, which makes it much easier to follow. See both the main program source code and the code of the subs that I used

Finally, they say "the old ones are the best", don't they? I so often write a demonstration to show context - how a list referred to in different ways can be output as all the elements jammed together, with the elements spaced out, or as just the number of elements in the list. Today's demonstration has its source code here on our site.