Perl question

Rusty Carruth plug-devel@lists.PLUG.phoenix.az.us
Mon May 28 21:24:01 2001


Carl Parrish wrote:
> 
> Thanks everyone. Man I've learned a *lot* about system time in the last
> two days.  $ENV{TZ} ended up working for me. Except that there is no
> US/Eastern zoneinfo file on the freeBSD servers I set this up on. So on
> those I ended up using America/New_York. However there is no
> America/New_York files on the Linux boxes. So right now they are set for
> US/Eastern. They all seem to be more or less on the same time. Does
> anyone know if I can leave it like this. Also while its fine right now.
> I ended up with two different scripts for the same problem (abeit just
> one line of code changed). So I'll proably end up doing a check to see
> what kind of server its on. But I don't know how NetBSD, OpenBSD,
> Solaris and other versions of Linux will look like.
> 
You know, what I'd do is probably something like this:

file: /etc/<program>/timezone
contents: timezone that THIS machine uses for EST
(if you don't want to fiddle with /etc, put it in as part of your install
process for your script)

then your perl program is the same for ALL platforms, and instead of
$ENV{TZ}='hard coded string';

you'd say something like (I'm still moderatly new to perl programming, so
excuse any baby-isms ;-)

my $tz = "some default";
my $tzfile = "/etc/theprogram/timezone";

if ( (-e $tzfile) && ( -r $tzfile ) ) # make sure its there and readable
{
	open( TZFILE, $tzfile) || die "this cannot happen, we've checked it! Oh, well.  Stopped";
	# surely there's a better way to read a single line than the below, 
	# (sure I'll find out sometime ;-)
	while(<TZFILE>)
	{
		$tz = $_;
	}
	# the truly paranoid would verify that $tz makes sense, eh?
	$ENV{TZ} = $tz;
	close TZFILE;  # don't forget to close it!
}

> Is there some source
> I can go to to find a standard set of zoneinfo files? Or if not just a
> listing of zoneinfo files on different *nix boxes?

I suppose you could open the zoneinfo dir and see whats there.
Or you could have the systems set up to have a specific zoneinfo file
that you use, but this requires that the admin who installs the machine
remember to do it..

rc