(untested) (updated to add more transformations)
#!/usr/bin/perl
# usage: $0 [-d "delimiter"] file
use strict;
use warnings;
my $delimiter = '\t';
if ( $ARGV[0] =~ /^\-(.)$/ ) {
$_ = $ARGV[1];
if ( /^\"(.*)\"$/ ) {
$delimiter = $1;
shift @ARGV; shift @ARGV;
}
}
my $file = join( '', @ARGV );
my %seen = ();
open my $fh, "<$file" or die "$!: $file\n";
while( <$fh> ) {
chomp;
my @cols = split( /$delimiter/ );
for ( my $col=0; $col <= $#cols; $col++ ) {
Check ( \%seen, $col[$col], $., $col+1 );
}
}
close $fh;
sub Check {
my ( $sref, $col, $lno, $colno ) = @_;
my $lc = Transform( $col );
my $xref;
if ( $xref = $sref -> { $lc } ) {
( $sref -> { $lc }{ $col } )
or print "Column $colno, Line $lno: ($col) "
. "varies from "
. ( values %$xref );
}
else {
$sref -> { $lc }{ $col } = "Column $colno, Line $lno: ($col)\n
+";
}
}
sub Transform{
my $lc = lc( shift());
# example of an additional transformation...
$lc =~ s/\s*//g;
return $lc;
}