Perl code fragments


Sometimes, rather than wade through loads of code just to find a small fragment that does what you want, it is useful to have fragments of code on their own and isolated. That way, you can find the code you want easily, and in some cases just place it straight into the main program, or replace an existing code fragment, with minimal changes. With that in mind, we have put together a few code fragments that have tended to be used repeatedly.

Determining which Perl modules are installed

To find out all Perl modules installed on your system, including those without documentation or outside the standard release, just do this:

find `perl -e 'print "@INC"'` -name '*.pm' -print

Splitting a single string into 2 user controlled output strings

Sometimes it is possible to solve a Perl string problem without a regular expression. The following code is for one of those occasions. The code takes an input string, and splits it into 2 output strings, with the split occurring on a user specified control character (In this case, a ':' character).

@array = split (":",$input_string,2);
$output_string1 = $array[0];
$output_string2 = $array[1];




www.cyberthinc.com