Data::Table error

[email protected] (David Newman)
Newsgroups perl.beginners
Organization Network Test Inc.
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.