s_gaurav1091 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am suppose to write a wrapper script on linux(first of all i dont know what is a wrapper script)which will take an output from a simulator and depending upon the output prepares and sends a xml udp message to some machine.Can anyone suggest some links or refrences about witting a wrapper script or can anyone tell from where to start with?plz help

Replies are listed 'Best First'.
Re: about a wrapper script
by Hue-Bond (Priest) on Dec 19, 2005 at 09:23 UTC

    A wrapper is a program that internally calls another program and performs some further actions. For example, I could write a Perl script that run ls and changed the file sizes to hexadecimal.

    So, based on your description, I think your program would be more like a filter than a wrapper. A filter is a program that takes the output of another program and modifies it in some way.

    I suppose your script will be run either at the right side of a pipe (that is, simulator | your_script) or stand alone, in which case it would take the output from a log file or so. In any case, you'll have to read new lines as they are generated and act accordingly.

    If you're at the right of a pipe, you read from STDIN as usual; if you have to work with a log, you can use File::Tail. For the XML I don't know but a search on CPAN will surely be enlightening.

    --
    David Serrano

Re: about a wrapper script
by holli (Abbot) on Dec 19, 2005 at 09:34 UTC
    For the udp part, there is Net::UDP which provides services for UDP communications over sockets. It is layered atop the Net::Inet and Net::Gen modules, which are part of the same distribution (Net-ext).


    holli, /regexed monk/
Re: about a wrapper script
by salva (Canon) on Dec 19, 2005 at 10:32 UTC
    Usually, sending XML over UDP is not a very good idea.

    UDP packet size is limited by the MTU of the network (tipically something between 400 and 1500bytes) and XML is very verbose and would probably generate messages larger than that.

    So, first, ensure all your messages fit in UDP packets or send them over TCP or use a binary format to encode your data (for instance RPC).

Re: about a wrapper script
by SheridanCat (Pilgrim) on Dec 20, 2005 at 03:03 UTC
    Here's a very naive wrapper. It wraps the Windows "dir" command. Just pass it a path. Again, very naive, you won't want to use this for anything but a demo.
    #!/usr/bin/perl use warnings; use strict; my $path = shift; my $output = `dir $path`; $output =~ s/DIR/FOO/g; print $output;