in reply to TimeZone Assistance Requested

First, welcome at the Monastery.  There are a couple of issues with your code, but as it's time to go to bed in my local TZ, I hope some other kind monks will point them out :)

Anyhow, if the idea is to convert those dates (with any TZ) into EST, the whole thing can be simplified considerably, because Date::Manip already does most of the magic while parsing the input string...

#!/usr/bin/perl -w use strict; use Date::Manip; Date_Init("TZ=EST"); # target TZ # use your filehandle here instead of DATA while (my $date_anyTZ = <DATA>) { chomp $date_anyTZ; # get rid of '~' to make date parseable by Date::Manip $date_anyTZ =~ tr/~/ /; my $date_EST = UnixDate(ParseDate($date_anyTZ), "%Y-%m-%d %H:%M:%S + %Z"); printf "%-24s --> %s\n", $date_anyTZ, $date_EST; } __DATA__ 20050526~18:15:06 GMT 20040401~01:12:02 GMT 20060201~00:59:01 GMT 20060401~01:01:01 EST 20040201~10:10:01 -0600 20010901~04:23:05 -0400 20050526~18:15:06 GMT 20040401~01:12:02 GMT 20000101~00:59:01 -0200 19841223~04:22:06 MST

Prints

20050526 18:15:06 GMT --> 2005-05-26 13:15:06 EST 20040401 01:12:02 GMT --> 2004-03-31 20:12:02 EST 20060201 00:59:01 GMT --> 2006-01-31 19:59:01 EST 20060401 01:01:01 EST --> 2006-04-01 01:01:01 EST 20040201 10:10:01 -0600 --> 2004-02-01 11:10:01 EST 20010901 04:23:05 -0400 --> 2001-09-01 03:23:05 EST 20050526 18:15:06 GMT --> 2005-05-26 13:15:06 EST 20040401 01:12:02 GMT --> 2004-03-31 20:12:02 EST 20000101 00:59:01 -0200 --> 1999-12-31 21:59:01 EST 19841223 04:22:06 MST --> 1984-12-23 06:22:06 EST

which looks OK to me.

Replies are listed 'Best First'.
Re^2: TimeZone Assistance Requested
by Knoperl (Acolyte) on Jul 30, 2007 at 14:42 UTC
    Thank you Almut for the code and everyone else for your assistance. I worked on it and it works good. Here is the code:
    #!/usr/bin/perl -w use strict; use Date::Manip; Date_Init("TZ=EST"); # { my $input =$ARGV[0]; #returns filename from command line my $date_anyTZ; chomp $input; #strip the carriage return open (DATAFILE, "$input")|| die ("Can not open $input:!\n"); #access the file while (my $date_anyTZ=<DATAFILE>) { chomp $date_anyTZ; # get rid of '~' to make date parseable by Date::Manip $date_anyTZ =~ tr/~/ /; my $date_EST = UnixDate(ParseDate($date_anyTZ), "%Y-%m-%d %H:%M:%S %Z"); printf "%-24s --> %s\n", $date_anyTZ, $date_EST; } close (DATAFILE); }