The data looks like this:
26047|9/26/02|js|XBRV|893 Ronson Road||San Francisco|CA|96666|Matt|666 +-650-5114|matt@somewhere.com|710464|1|9/27/02|9/27/02|warranty|Yes| 26048|9/26/02|js|BEVT|13 West Kennedy Blvd.||Yourtown|FL|33456|Christi +an Carusso|713-867-1515||Tel-14|1|||non warranty ``cross ref: 26048|| 26049|9/26/02|js|Ultimate Products|1 South Sunset Drive||Tempe|AZ|8333 +1|Mike Goose|700-676-6006|goose@nowhere.com|RS-502,CC-95|1 each|||S/N + A145902||
What I need to do is change the format of the dates (if they exist) in fields 1, 14, & 15 from the current 9/26/02 format to 26-Sep-2002 format. Thanks to a posting by davorg I think I have a handle on how to do the conversions.
Where I am having a problem is testing if the date fields has data in it (I think):
Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 91, <IN> line 1. Use of uninitialized value in numeric lt (<) at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 91, <IN> line 1. Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 92, <IN> line 1. Use of uninitialized value in numeric lt (<) at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 92, <IN> line 1. Use of uninitialized value in join or string at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 103, <IN> line 1. Use of uninitialized value in join or string at /usr/lib/perl5/5.6.1/T +ime/Local.pm line 103, <IN> line 1. Can't handle date (0, , , 7, 8, -1899) at ./convertdates.pl line 27
Any pointers are appreciated!
#!/usr/bin/perl -w use strict; use Time::Local; my $in_file="default.db"; my $out_file="properdates.db"; my ($sec, $min, $hr)=0; my @fmt_date=''; my @new=''; open (IN,"$in_file")||die "Sorry, but I can't open the file:$!"; open (OUT,">$out_file")||die "Sorry, but I can't append the file:$!"; while(<IN>){ chomp; my @line=split(/\|/); my @date=(split/\|/)[1,14,15]; foreach my $i (@date){ if ($i){ #my ($d, $m, $y)=split/\//, $date[$i]; my ($d, $m, $y)=split/\//, $i; $y-=1900; --$m; my $epoch=timelocal($sec, $min, $hr, $d, $m, $y); ($fmt_date[$i])=strftime('%d-%b-%Y', localtime($epoch)); } #end if } #end foreach push @new, qq($line[0]|$fmt_date[0]|$line[2]|$line[3]|$line[4]|$line +[5]|$line[6]|$line[7]|$line[8]|$line[9]|$line[10]|$line[11]|$line[12] +|$line[13]|$fmt_date[1]|$fmt_date[2]|$line[16]|$line[17]|$line[18]); push @new, "\n"; } #end while print OUT "@new"; close IN; close OUT;
Edited by footpad, ~ Sat Sep 28 02:01:00 2002 (UTC) : Placed <code> tags around error messages, per Consideration.
In reply to Formatting dates by cajun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |