SysTools

Download Source

Package with handy routines. Currently can untaint a file name (string) and process options, as well as generate random file names.

untaintFile

Check a filename for invalid characters ( like pipe symbols that could pipe into 'rm -r /' and other nasty things). Needed when running with -T (taint mode).

Syntax: $string = untaintFile ( "tainted_string" );

Parameter:

tainted_string
a string that is supposed to be a file name.

Returns: untained string.

getOpt

Filter options out of a string containing of groups of characters seperated by spaces, as in print "@ARGV". When passing @ARGV, be sure to either escape or quote it!. This will interpret a group of charcters starting with '-' as a string of one-letter options. If an one-letter option in the string requires an argument, the rest of the string will be gobbled up to satisfy it. Failing that, the next word will be taken, regardless. Any words not starting with '-' and not used as argument to an option will be taken to be a positional argument (relative to other arguments, not hampered by any interfering options) and returned as a seperate array.

Syntax: getOpt ( "string to filter" , "<valid options>" );

Valid options are passed as a string, or an array reference where an option requiring an argument is followed by a ':' (as in unix). e.g. "ab:c" will cause the options -a, -b and -c to be recognised and -b will have an argument.

Sets and exports:

@OPTS
options found in "string to filter".
@ARGS
arguments found in "string to filter" (in order: first argument is 0).
%OPTARG
hash of arguments that go with options. The option requiring an argument is the key. Options not requiring arguments will not be included!

E.g.: the code line getOpt( \@ARGV , "ab:c" ); will, if the program is called as test.pl -a -c -b test test1 test2 result in the following array and hash values being set:

genFileName

This function returns a random filename consisting of the data with a 1-3 digit random number attached, in the format: PREFIXtmpMMDDHHMISS###.SUFFIX.

synopsis: $new_name = genFileName( PREFIX => 'prefix', SUFFIX => 'suffix' );

Parameters:

PREFIX
string to be collated with the generated filename string.
SUFFIX
string to be attached to the end of the generated filename string.