I'm having an odd problem. I have a little program to read a CSV file using Text::CSV.
#!/usr/bin/perl
use v5.10 ;
use strict;
use warnings ;
use Text::CSV ;
print "DB FILE: " ;
my $dbfile = <STDIN> ;
chomp($dbfile) ;
my $if;
open ($if, "<", $dbfile) or die "Can't open $dbfile: $!\n" ;
my $csv = Text::CSV->new() ;
$csv->sep("\t") ;
my $header = $csv->getline($if) ;
say $header ;
exit ;
When I run it I get:
D:\Desktop>testcsv
DB FILE: alladdrs.csv
Use of uninitialized value $header in say at D:\perl\testcsv.pl line 2
+2, <$if> line 1.
The header line in the file is:
Importance,"First Name","Middle Name","Last Name","Full Name",Company,
+Department,"Job Title","Street (b.)","City (b.)","State (b.)","ZIP Co
+de (b.)","Country/Region (b.)","Home Phone","Business Phone","Mobile
+Phone","Business Phone 2","Business Phone 3","Business Phone 4","Busi
+ness Fax","Business Web Page","Street (h.)","City (h.)","State (h.)",
+"ZIP Code (h.)","Country/Region (h.)","Home Phone 2","Home Phone 3","
+Home Phone 4","Home Fax","Personal Web Page","Mobile Phone 2","Mobile
+ Phone 3","Mobile Phone 4",E-mail,"E-mail 2","E-mail 3","E-mail 4",x,
+y,z,w,Office,Supervisor,Assistant,Salutation,Nickname,Gender,Spouse,B
+irthday,Anniversary,Family,Hobbies,Specialty,Strengths,Personality,No
+tes,"Custom 2","Custom 3","Custom 4","Custom 5","Custom 6","Custom 7"
+,"Custom 8",Comment,Group,"Birthday Reminder On/Off","Anniversary Rem
+inder On/Off"
with the proviso that the first three
invisible characters in the file are "efbbbf" which I gather is some unicode magic. Could that be causing the problem? If so, since the file is actually 100% ISO-Latin {except for the first three characters :o)} is there some way to get perl
and the text::csv to ignore them and read and parse the header record?