Wednesday, January 30, 2008

Perl Scripts

Perl script that I wrote

#!/usr/bin/perl
# validHPFF.pl

# Command Line Arguement processing
$numArgs = $#ARGV + 1;
if($numArgs == 1) {
# print "Input Directory = $ARGV[0]\n";
} else {
print "Not enough command line arguements were provided\n";
die "Usage: validHPFF.pl \n";
}

#Now get input directory and start to generate files into output directory
$currentPath = `pwd`;
chop($currentPath);
$inputDir = $currentPath . "/" . $ARGV[0];
# print "Input Directory = " . $inputDir . "\n";
#opendir(DIRHANDLE,$inputDir);
opendir(DIRHANDLE,$ARGV[0]);
@files = readdir(DIRHANDLE);
foreach $file (@files) {
if ( index($file, '.OUT') != -1) {
$infile = $ARGV[0] . '/' . $file;
open(INFILE, "$infile") or die "could not open $infile\n";
print "Validating file: " . $file . "\n";
$firstTime = 1;
# This while statement will load each line from infile
# and place its contents into a variable called $_
# and iterate through the file until EOF
$fileLineCount = 0;
while( ) {
$fileLineCount = $fileLineCount + 1;

# Header Section
if(m/^H/) {

# Validation section
@headerFields = split(/\/, $_);
$hfCount = 0;
foreach my $field (@headerFields) {
$hfCount = $hfCount + 1;
# print "header field " . $hfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Header field " . $hfCount . " is empty\n";
print "Error: Line number " . $fileLineCount . "\n";
}
}
if ( $hfCount != 2) {
print "Error: Header didn't have enough fields: " . $hfCount . " expected 2\n";
print $_ . "\n";
}
}

# Now check Account
if(m/^A/) {

# Validation section
@accountFields = split(/\/, $_);
$afCount = 0;
foreach my $field (@accountFields) {
$afCount = $afCount + 1;
# print "account field " . $afCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Account field " . $afCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $afCount != 3) {
print "Error: Account didn't have enough fields: " . $afCount . " expected 3, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# Billsummary section
if(m/^B/) {

# Validation section
@billsummFields = split(/\/, $_);
$bfCount = 0;
foreach my $field (@billsummFields) {
$bfCount = $bfCount + 1;
# print "billsumm field " . $bfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: Billsumm field " . $bfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $bfCount != 9) {
print "Error: Billsumm didn't have enough fields: " . $bfCount . " expected 9, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# P Member section
if(m/^PM/) {
# $reportHash{"PM"} = $reportHash{"PM"} + 1;

# Validation section
@pmFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pmFields) {
$pfCount = $pfCount + 1;
# print "pm field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($pfCount != 7) && ($pfCount != 9) && ($pfCount != 6) ) {
print "Error: PM field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $pfCount != 10) {
print "Error: PM didn't have enough fields: " . $pfCount . " expected 10, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# PR section
if(m/^PR/) {
# $reportHash{"PR"} = $reportHash{"PR"} + 1;

# Validation section
@pmFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pmFields) {
$pfCount = $pfCount + 1;
# print "pr field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($pfCount != 6) && ($pfCount != 8) && ($pfCount != 9) ) {
print "Error: PR field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $pfCount != 10) {
print "Error: PR didn't have enough fields: " . $pfCount . " expected 10 fields, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# RA section
if(m/^RA/) {
# $reportHash{"RA"} = $reportHash{"RA"} + 1;

# Validation section
@raFields = split(/\/, $_);
$rfCount = 0;
foreach my $field (@raFields) {
$rfCount = $rfCount + 1;
# print "RA field " . $rfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($rfCount != 6) && ($rfCount != 7) && ($rfCount != 8) &&
($rfCount != 10) && ($rfCount != 11) && ($rfCount != 12) &&
($rfCount != 13) ) {
print "Error: RA field " . $rfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $rfCount != 15) {
print "Error: RA didn't have enough fields: " . $rfCount . " expected 15, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# RD section
if(m/^RD/) {
# $reportHash{"RD"} = $reportHash{"RD"} + 1;

# Validation section
@rdFields = split(/\/, $_);
$rfCount = 0;
foreach my $field (@rdFields) {
$rfCount = $rfCount + 1;
# print "RD field " . $rfCount . ": $field\n";
if ( length($field) == 0) {
if ( ($rfCount != 7) && ($rfCount != 8) && ($rfCount != 11) ) {
print "Error: RD field " . $rfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
}
if ( $rfCount != 13) {
print "Error: RD didn't have enough fields: " . $rfCount . " expected 13, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# P section
if(m/^P\/) {
# $reportHash{"P"} = $reportHash{"P"} + 1;

# Validation section
@pFields = split(/\/, $_);
$pfCount = 0;
foreach my $field (@pFields) {
$pfCount = $pfCount + 1;
# print "P field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: P field " . $pfCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $pfCount != 13) {
print "Error: P didn't have enough fields: " . $pfCount . " expected 13, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}

# Footer section
if(m/^F/) {
# $reportHash{"F"} = $reportHash{"F"} + 1;

# Validation section
@fFields = split(/\/, $_);
$fCount = 0;
foreach my $field (@fFields) {
$fCount = $fCount + 1;
# print "F field " . $pfCount . ": $field\n";
if ( length($field) == 0) {
print "Error: F field " . $fCount . " is empty, line number " . $fileLineCount . "\n";
}
}
if ( $fCount != 2) {
print "Error: F didn't have enough fields: " . $fCount . " expected 2, line number: " . $fileLineCount . "\n";
print $_ . "\n";
}
}
}

close (INFILE);
}
}

Friday, January 25, 2008

Eclipse Plugins

I have found a number of interesting articles over the years regarding eclipse that I think it would be useful to document for later referal:

Sangam Eclipse Plugin: http://sangam.sourceforge.net/
Useful for pair programming