20070608 checkfieldspl - plembo/onemoretech GitHub Wiki

title: checkfields.pl link: https://onemoretech.wordpress.com/2007/06/08/checkfieldspl/ author: lembobro description: post_id: 692 created: 2007/06/08 20:18:00 created_gmt: 2007/06/08 20:18:00 comment_status: open post_name: checkfieldspl status: publish post_type: post

checkfields.pl

This is one of those works-in-progress that may have some use to others, so I’ll share it here.

Our Oracle DBA’s called this morning wanting to know if the length of any of the fields in a delimited file I send them changed (got longer). I told them I had no idea. LDAP, I patiently explained, doesn’t care about field length. This is one of the reasons it’s easier to use as a white pages platform (not having to keep track of how many characters are in the surname in each entry is a real blessing in a global enivonment).

Anyway, because I’m such a nice guy I told them I’d go find out what the largest number of characters were in each field of the file.

Here’s another of my (infamously) simplistic Perl scripts that I used to get the info:

`

#!/usr/bin/perl
# checkfields.pl Audit a delimited LDAP feed
# Read in pipe-delimited feed, count number of chars in each field to get
# highest total. For use in reporting number of chars that import needs to
# accomodate for each field.
#
use Text::ParseWords;
my $HOME = $ENV{'HOME'};
my $feedfile = "$HOME/tmp/ldap.dat";
my %wholefeed;
my $totfields;
print "Checking $feedfilen";
open FH, "<$feedfile" or die $!;
while (<FH>) {
    my @line = &parse_line('|',0,$_);
    $totfields = scalar(@line);
    my $fieldct =0;
    my $index = @line[0];
    foreach my $field(@line) {
        my $fieldno = $fieldct++;
        my $newlen = length($field);
        my $oldlen = $wholefeed{$fieldno};
        if ($newlen >$oldlen) {
            $wholefeed{$fieldno} = $newlen;
        }
    }
}
print "Total Fields: $totfieldsn";
print "Field,Charsn";
my $count;
for ($count =0; $count <$totfields; $count++) {
    print $count, ",", $wholefeed{$count}, "n";
}
#
__END__;

`

Copyright 2004-2019 Phil Lembo