PERL

By

Andrew Pitonyak


HOMEBookConferencesOpenOffice.org MacrosDatabaseSpamPerlMy Perl UtilitiesVYMMiscMagic

I have two primary perl sections, my general utilities and my spam utilities. Just in case it is not obvious, the link general utilities loads a page that allows you to see these utilities including the source code. The other link, spam utilities, is for the same purpose.

General Utilites

Spam Utilites

These were written so that I could avoid spam on my computer. There is a better write-up here and the utilities are here.

Formatting And Extracting Dates And Times In Perl

There are two primary reasons that people come to my website if they do not already know me. The primary reason is of course Macro Programming using OpenOffice. The second reason is to try and figure out how to parse dates and times using PERL. If your only purpose in life is to format and use dates and times, then simply download a copy of my date utility code. You can see a pretty version of it if you like, or simply see how to use it.

If you want to do it the hard way - meaning you want to do it yourself - it is not that difficult. First, call the time() function to find out what time it is. Next, pass this value to localtime function to break this value into component pieces.

$a_time = time();
( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = ( localtime($a_time) );

The returned year is the number of years from 1900, so the year 2004 is returned as 104. Boy did this annoy some of my PERL programming friends! I must admit that I used some interesting code in the time_date_str routine, take a look at it. If there is call for it, then I will provide some more information.

File
Changed
Size
Pretty Version
POD Doc
Description
ADPLogger.pm December 11, 2009 05:36:27 PM EST 32924 bytes ADPLogger.pm.html ADPLogger.pm.pod.html This logger is able to configure itself using a ConfigFileParser, so a simpler configuration method exists. Also, the class is able to limit the log file size and create rolling log files. For example, if the maximum file size is 10K, you may have files named x.log, x.log.1, x.log.2, etc... each of size 10K or less. In this document, I only explain the small logger, but the code is very similar.
BayesianTokenCounter.pm December 11, 2009 05:36:28 PM EST 43094 bytes BayesianTokenCounter.pm.html BayesianTokenCounter.pm.pod.html I wrote this to parse email files with PMMail. I used the results to classify email as SPAM, or not SPAM.
CommandLineProcessor.pm December 11, 2009 05:36:29 PM EST 22189 bytes CommandLineProcessor.pm.html CommandLineProcessor.pm.pod.html
ConfigFileParser.pm December 11, 2009 05:36:29 PM EST 20116 bytes ConfigFileParser.pm.html ConfigFileParser.pm.pod.html Read property files of the form "property = value". Many advanced capabilities are supported such as the ability to reference already defined properties. Advanced regular expressions are demonstrated to track things like an even or odd number of preceding escape characters.
DateUtil.pm December 11, 2009 05:36:30 PM EST 17263 bytes DateUtil.pm.html DateUtil.pm.pod.html Provides easy formatting of dates and times, and also, the conversion of a formatted date and time back to the system representation. See also test_strings_and_dates.pl and test_year_2038.pl.
DeepCopy.pm December 11, 2009 05:36:30 PM EST 3253 bytes DeepCopy.pm.html DeepCopy.pm.pod.html A hash or array may contain a reference to an object. A hash or array copy continues to reference the original object. This library demonstrates how to copy references as a new object.
SafeGlob.pm December 11, 2009 05:36:30 PM EST 17079 bytes SafeGlob.pm.html SafeGlob.pm.pod.html The section begins by discussing on creating classes in PERL. The library itself, provides a method to find files and directories using file specs or regular expressions. The returned values can be done recursively.
SmallLogger.pm December 11, 2009 05:36:31 PM EST 35725 bytes SmallLogger.pm.html SmallLogger.pm.pod.html Simple log class with output to the screen or file. Uses my XMLUtil library, which uses the XML::Parser, for configuration.
SmallLoggerNoXML.pm December 11, 2009 05:36:32 PM EST 29518 bytes SmallLoggerNoXML.pm.html SmallLoggerNoXML.pm.pod.html The SmallLogger, but without XML capabilities. For many things, this is sufficient, and you do not need to install the XML::Parser. This library is not listed or described in this document.
SocketUtil.pm December 11, 2009 05:36:32 PM EST 32282 bytes SocketUtil.pm.html SocketUtil.pm.pod.html Demonstrates how to read and write sockets with many details abstracted away. I found this library particularly useful for writing test harnesses to communicate with socket driven programs.
StringUtil.pm December 11, 2009 05:36:33 PM EST 30883 bytes StringUtil.pm.html StringUtil.pm.pod.html String type utilities to format, remove space, and display numbers with leading zeros. Unexpected methods provide the ability to find the maximum width of all strings in an array or hash, or the ability to convert any object to a string.
XMLUtil.pm December 11, 2009 05:36:33 PM EST 15244 bytes XMLUtil.pm.html XMLUtil.pm.pod.html Convert arbitrary objects to and from XML. I am not certain how useful the library is, but it demonstrates how to recognize object types.


Last Modified July 5, 2010 10:00:37 AM EDT© 1999-2017 Andrew Pitonyak (email me at: andy @ pitonyak.org)