Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

II. Answers > P. Answers to Chapter 16 Exercises

Appendix P. Answers to Chapter 16 Exercises

Answer 16.1: Set the environment variable TZ by replacing its value in the %ENV hash. The value you need to set varies from system to system and, at least on a Unix machine, you use the names of files in /usr/share/zoneinfo. For the Pacific time zone, some systems use PST8PDT. After that, use exec to turn your perl process into the date command, which has the same environment as the perl process. You’ve effectively created a wrapper that sets up the environment then executes the desired command:

#!/usr/bin/perl
use strict;
use warnings;

$ENV{TZ} = 'PST8PDT';

exec 'date';

On a Mac OS X system, you have to use US/Pacific:

#!/usr/bin/perl
use strict;
use warnings;

$ENV{TZ} = 'US/Pacific';

exec 'date';

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint