Oct 202014

Most perl scripts read the data that will be processed, and write the result, from/to several sources: files, databases, keyboard, literal strings in the source code of the script…

Text data read from these sources might be encoded in different character encodings. The most common encodings are utf8 and latin1 (ISO 8859-1). To make sure that those data will be adequately processed, it is highly recommended to always specify explicitly the expected encoding of input data, and the desired encoding of output data, as explained in this post.

Continue reading »

 Posted by at 6:25 pm
Jul 032014

JSON and XML are to formats commonly used to represent structured data in a text file. Sometimes, data exported from a tool in JSON format needs to be imported in a different tool that only accepts XML as input.

This post explain how to perform the conversion from JSON to XML using a perl script.

Continue reading »

 Posted by at 11:38 am
May 272014

The process flow of a perl script (or a program in any other language, actually) usually starts reading information for one or several sources: files on disk, databases, network connections, input from the keyboard… Next, it processes this information, and finally delivers the result writing it to a file, storing it in a database, sending it through a network connection, displaying it on screen,…

In some cases, this flow can be split into several sub-tasks, each of which follows the same schema of reading, processing and writing the data.

In these cases, the performance of the script can be greately enhanced if these tasks are executed in parallel. In that way, while some sub-tasks may be waiting to receive information from the network, some others may be using the CPU to perform the processing of data, and some others may be waiting for a disk I/O operation to finish.

This post explains how to program a perl script to execute concurrently several subprocesses, thus optimizing the usage of the available resources.

Continue reading »

 Posted by at 10:45 am
Oct 242013

A previous post in this blog explains How to fetch the content of a URL in perl,   using the LWP::UserAgent module available from CPAN.

But it might happen that the machine where the script is going to be run does not have direct access to internet, and the request must be sent through a proxy servere. This post explains how to make the request in this case.

Continue reading »

 Posted by at 12:18 pm
Oct 222013

A common operation where it is desirable to set a timeout is when a server is communicating with other servers or clients through the network.

The server sends a message to the other servers, and waits for answers. But there might be network issues, or some of the other servers might have become unresponsive for some reason, and this should not block the other communications going on.

Continue reading »

 Posted by at 8:24 am