in reply to Re: changing a string to a useable date time
in thread changing a string to a useable date time

Hi L-R, I get the following message when I run your code:

Perl_programs/2005_perl_programs> perl LR_date_time_convert.pl
Global symbol "$st" requires explicit package name at LR_date_time_convert.pl line 22.
Execution of LR_date_time_convert.pl aborted due to compilation errors.
## OPEN input file for reading open (IN, "1998_wind_date_time.txt") or die "Couldn't open 1998_wind_d +ate_time.txt "; ## OPEN input file for reading open (OUT, ">1998_wind_formatted_data2.out") or die "Couldn't open 199 +8_wind_formatted_data2.out"; #!/usr/bin/perl use strict; use warnings; use Time::Local; use POSIX 'strftime'; my $str = '19980730010031'; my $epoch = get_epoch( $str ); print strftime("%m/%d/%Y", localtime($epoch)); sub get_epoch { my $str = shift; my ($yr, $mon, $day, $hr, $min, $sec) = unpack('A4A2A2A2A2A2', $st +r); $mon--; return timelocal($sec, $min, $hr, $day, $mon, $yr); }

Replies are listed 'Best First'.
Re^3: changing a string to a useable date time
by Limbic~Region (Chancellor) on Feb 01, 2005 at 16:31 UTC
    cpiety,
    That is a copy/paste error on your part. You should use the 'download code' link instead. As you can see
    my ($yr, $mon, $day, $hr, $min, $sec) = unpack('A4A2A2A2A2A2', $st +r);
    Should be
    my ($yr, $mon, $day, $hr, $min, $sec) = unpack('A4A2A2A2A2A2', $str);

    Cheers - L~R

      thanks, it runs now. I guess Perl ignores white space but not "+r"!
      Thanks for your patience.
      I am not a programmer and decided to try and learn PERL to process some data.
      Frankly....It is kicking my butt.