#! c:\xampp\perl\bin\perl use strict; use warnings; use LWP::Simple; use Time::Local; my $standard_filename = $ARGV[0]; my $extended_filename = $ARGV[1]; # Get yesterdays date time my $epoc = time(); $epoc = $epoc - 86400; my $yesterday = localtime($epoc); my ($sec, $min, $hour, $day, $month, $year) = (localtime($epoc))[0,1,2,3,4,5]; $month++; $year += 1900; my $mm = $month; if ($month < 10) { $month = "0" . $month; } if ($day < 10) { $day = "0". $day; } # Build the Standard and Extended filenames if not passed as parameters if (not defined $standard_filename) { $standard_filename = "C:\\wdisplay\\logfiles\\" . $mm . $year . "lgcsv.csv"; } if (not defined $extended_filename) { $extended_filename = "C:\\WebHost\\customtextout.txt"; } # Load Standard File in to an Array my @standard_records; open (standard_file, "<", $standard_filename) or die "Failed to open file: $!\n"; while () { chomp; push @standard_records, $_; } close standard_file; # Load Extended File into an Array my @extended_records; open (extended_file, "<", $extended_filename) or die "Failed to open file: $!\n"; while () { chomp; push @extended_records, $_; } close extended_file; # Process each Standard Record foreach (@standard_records) { my @std_lines = split /\n/, $_; foreach my $line_std (@std_lines) { my @std_fields = split ",", $line_std; my $obs_day = $std_fields[0]; my $obs_month = $std_fields[1]; my $obs_year = $std_fields[2]; my $obs_hour = $std_fields[3]; my $obs_minute = $std_fields[4]; my $obs_seconds = 0; if ($obs_day eq "day") { next; } my $utc_time = timelocal($obs_seconds, $obs_minute, $obs_hour, $obs_day, $obs_month - 1, $obs_year - 1900); my ($utc_sec, $utc_min, $utc_hour, $utc_day, $utc_month, $utc_year) = (gmtime($utc_time))[0,1,2,3,4,5]; $utc_month++; $utc_year += 1900; if ($obs_day < 10) { $obs_day = "0" . $obs_day; } if ($obs_month < 10) { $obs_month = "0" . $obs_month; } if ($obs_hour < 10) { $obs_hour = "0" . $obs_hour; } if ($obs_minute < 10) { $obs_minute = "0" . $obs_minute; } my $record_line = $obs_year . "," . $obs_month . "," . $obs_day . "," . $obs_hour . "," . $obs_minute . "," . "00" . "," . "," . $utc_year . "," . $utc_month . "," . $utc_day . "," . $utc_hour . "," . $utc_min . "," . $utc_sec . "\n"; print $record_line; my $file = "C:\\WEATHER_DATA_COLLECTOR\\temp.csv"; open (TXT, ">>", $file); print TXT $record_line; close (TXT); } }