Libraries

Code Libraries are put in to packages. Create a file called “packagename.pm” in your Perl include Path.

package MyUtilities;
use strict;
 
sub currentTimestamp
{
  my ($attime) = @_;
  my ($Tsec, $Tmin, $Thour, $Tmday, $Tmon, $Tyear, $Twday, $Tyday, $Tisdst) = localtime( $attime || time() );
  return = sprintf "%04d-%02d-%02d %02d:%02d:%02d", $Tyear+1900, $Tmon + 1, $Tmday, $Thour, $Tmin, $Tsec;
}

To use it, do this!

use MyUtilities;
$now = MyUtilities::currentTimestamp();

There are ways to “export” subroutines from the package which automatically get imported into your namespace, but I do not recommend this (except with well-known or standard Perl packages) as it does not show where the function lives.

 
programming/perl/libraries.txt · Last modified: 2005/07/18 17:16 by allen