An update: This error from Table.pm:

> confess "Invalid column name (all digits): $elm at column ".($i+1)
> unless ($elm =~ /\D/);

would result if the input file's column names did not contain a non-digit character. That was definitely true before, where the column headings contained digits. But changing the column headings to "A", "B", "C" ... "CA" (ie, all cases match the \D test) still produces the same error:

/Library/Perl/5.8.8/Data/Table.pm:56:  Invalid column name (all digits):  at 
column 84

The input files have only 82 columns. I've looked at the CSV files in vi and TextWrangler and Excel and see no column 83 or 84 anywhere.

Thanks for any clues on what might be causing this error.

dn




On 5/26/08 8:33 PM, David Newman wrote:
I'm using Data::Table to compare two lists of contacts, both in CSV form. Running the script below produces this error:

/Library/Perl/5.8.8/Data/Table.pm:56: Invalid column name (all digits): at column 84

This is odd in that:

1. None of the column names are all digits (indeed, all begin with letters); and

2. There are only 82 columns total in both source files.

I previously tried running this on two much shorter input files (three records each, three columns each) and it ran fine.

A search for this error produced this bit from Table.pm:

confess "Invalid column name (all digits): $elm at column ".($i+1) unless ($elm =~ /\D/);

But I don't know how that applies here.

The script and the list of column names are pasted below.

Thanks for any clues on debugging this.

dn



#!/usr/bin/perl -w

use strict;

# comp2csv.pl - compare two CSV files

use Data::Table;

my $lfile = "file1.csv";
my $rfile = "file2.csv";
my ($l, $r);
my (@ldepth, @rdepth, @lwidth, @rwidth);
my ($bothcount, $lcount, $rcount) = (0, 0, 0);
my ($i, $j, $k, $y, $z) = (0, 0, 0, 0);
my ($lcomp, $rcomp);

# populate tables
$l = Data::Table::fromCSV($lfile);
$r = Data::Table::fromCSV($rfile);

# get table length and width
my $ldepth = $l->nofRow;
my $rdepth = $r->nofRow;
my $lwidth = $l->nofCol;
my $rwidth = $r->nofCol;
print "First file length: $ldepth :: Second file length: $rdepth\n\n";
# print "First file width: $lwidth :: Second file width: $rwidth\n\n";

# do comparison
# if they're both the same
print "THESE RECORDS APPEAR IN BOTH FILES\n\n";
for ($i = 0; $i < $ldepth; $i++) {
    for ($j = 0; $j < $rdepth; $j++) {
        # since we're not comparing whole rows,
        # grab elements to compare
$lcomp = $l->elm($i,"First Name") . " " . $l->elm($i,"Last Name") . " " . $l->elm($i,"Company") . " " . $l->elm($i,"Job Title"); $rcomp = $r->elm($j,"First Name") . " " . $r->elm($j,"Last Name") . " " . $r->elm($j,"Company") . " " . $r->elm($j,"Job Title"); if ($lcomp eq $rcomp) {
            for ($k = 0; $k < $rwidth; $k++, $bothcount++) {
                $z = $r->elm($j,$k);
                print "$z";
                print ",";
            }
            print "\n";
        }
    }
}

# if the name is only in lcomp
print "\nTHESE RECORDS APPEAR IN ONLY IN FILE 1\n\n";
for ($i = 0; $i < $ldepth; $i++) {
    $y = 0;
    for ($j = 0; $j < $rdepth; $j++) {
        # since we're not comparing whole rows,
        # grab elements to compare
$lcomp = $l->elm($i,"First Name") . " " . $l->elm($i,"Last Name") . " " . $l->elm($i,"Company") . " " . $l->elm($i,"Job Title"); $rcomp = $r->elm($j,"First Name") . " " . $r->elm($j,"Last Name") . " " . $r->elm($j,"Company") . " " . $r->elm($j,"Job Title"); if ($lcomp eq $rcomp) {
            $y = 1;
        }

    }

    if ($y == 0) {
        for ($k = 0; $k < $lwidth; $k++, $lcount++) {
                $z = $l->elm($i,$k);
                print "$z";
                print ",";
        }
            print "\n";
    }
}

# if the name is only in rcomp
print "\nTHESE RECORDS APPEAR IN ONLY IN FILE 2\n\n";
for ($i = 0; $i < $rdepth; $i++) {
    $y = 0;
    for ($j = 0; $j < $ldepth; $j++) {
        # since we're not comparing whole rows,
        # grab elements to compare
$lcomp = $l->elm($i,"First Name") . " " . $l->elm($i,"Last Name") . " " . $l->elm($i,"Company") . " " . $l->elm($i,"Job Title"); $rcomp = $r->elm($j,"First Name") . " " . $r->elm($j,"Last Name") . " " . $r->elm($j,"Company") . " " . $r->elm($j,"Job Title"); if ($lcomp eq $rcomp) {
            $y = 1;
        }

    }

    if ($y == 0) {
        for ($k = 0; $k < $rwidth; $k++, $rcount++) {
                $z = $r->elm($i,$k);
                print "$z";
                print ",";
        }
            print "\n";
    }
}


print "\nSUMMARY\n";
$bothcount = $bothcount / $rwidth;
$lcount = $lcount / $rwidth;
$rcount = $rcount / $rwidth;
print "$bothcount records in both files\n";
print "$lcount records in file 1\n";
print "$rcount records in file 2\n";

# END OF SCRIPT



and here are the column names:

First Name
Last Name
Title
Suffix
Nickname
Company
Job Title
Dept
Work Street Address
Work City
Work State
Work Zip
Work Country/Region
Work URL
Home Street Address
Home City
Home State
Home Zip
Home Country/Region
Home URL
Home Phone 1
Home Phone 2
Home Fax
Work Phone 1
Work Phone 2
Work Fax
Pager
Mobile Phone
Main Phone
Assistant Phone
Tom's cell
Work fax 2
Dick's cell
Harry's cell
Email Address 1
Email Address 2
Email Address 3
Email Address 4
Email Address 5
Email Address 6
Email Address 7
Email Address 8
Email Address 9
Email Address 10
Email Address 11
Email Address 12
Email Address 13
Instant Messaging 1
Instant Messaging 2
Instant Messaging 3
Instant Messaging 4
Instant Messaging 5
Instant Messaging 6
Instant Messaging 7
Instant Messaging 8
Instant Messaging 9
Instant Messaging 10
Instant Messaging 11
Instant Messaging 12
Instant Messaging 13
Custom 1
Custom 2
Custom 3
Custom 4
Custom 5
Custom 6
Custom 7
Custom 8
Custom date 1
Custom date 2
Spouse
Birthday
Anniversary
Notes
Age
Astrology sign
Bloodtype
Furigana Company Name
Furigana First Name
Furigana Last Name
Furigana Spouse Name
Interests




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to