Utility - Module for uncategorized functions.


  use PIRL::Utiilty;

  Timestamp ()
  Command_Status ($command, $expected, $message)


This module contains functions that do not fall into one of the other PIRL PERL modules. It currently provides functions to get a timestamp string, or to check the exit status of the last command run.



Produces a formatted string representation of the current local time. The local time is based on the timezone the user's system. The format for the timestamp string is as follows:



Year number

Month number (01-12)

Day of the month (01-31)

Hour of the day (00-23)

Minute of the hour (00-59)

Second of the minute (00-59)




Returns the current local time as a formatted string.


If the current local time is 18 seconds after 11:26 pm on April 11, 2006 then Timestamp () will produce the string "2006-04-11T23:26:18".


The status of an external command is checked. The last external command that has been run will have its exit status in the $? built-in PERL variable. This value is checked to ensure that the command was actually run and, if so, that the exit status was the expected value. If either check fails an appropriate error message is created.


$command - The command string that was issued

$expected - The expected integer exit status of the command

$message - A command failure message; this may be undef.


If either the command failed to run or did not produce the expected exit status an appropriate error message is returned (not printed); otherwise false (0) is returned.

The error message has the form:

    Problem description

If the command could not be executed the "Problem description" is:

    Command could not be executed!

otherwise, if the exit status does not equal the expected value, it is:

    Command failed - expected exit status $expected, obtained $status.


    $command = "process -file $data_file";
    $message = `$command 2>&1`;
    $report = Command_Status ($command, 0, $message);
    print STDERR $report
        if $report;

The $command line is executed by a host shell with both STDOUT and STDERR captured in the $message variable. The exit status of the command is checked for the expected result of 0. If the exit status was 0, nothing is printed; otherwise an error message is printed to STDERR that includes any output from the command.


Drew Davidson and Bradford Castalia, UA/PIRL


Copyright (C) 2005, 2006 Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


1.4 2006/04/12 18:08:27