BernieC has asked for the wisdom of the Perl Monks concerning the following question:
When I run it I get:#!/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 ;
The header line in the file is: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.
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?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"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: trouble with text::csv
by tangent (Parson) on Dec 05, 2021 at 01:59 UTC | |
by Tux (Canon) on Dec 05, 2021 at 09:55 UTC | |
by tangent (Parson) on Dec 05, 2021 at 14:16 UTC | |
Re: trouble with text::csv
by LanX (Saint) on Dec 05, 2021 at 00:20 UTC | |
by BernieC (Pilgrim) on Dec 05, 2021 at 15:44 UTC | |
by LanX (Saint) on Dec 05, 2021 at 15:47 UTC | |
by BernieC (Pilgrim) on Dec 05, 2021 at 15:51 UTC | |
by LanX (Saint) on Dec 05, 2021 at 17:58 UTC | |
by Anonymous Monk on Dec 05, 2021 at 18:57 UTC |