#!/usr/local/bin/perl
## This program takes one optional parameter to locate the file
## or it will request a file name and look in the current dir.
## There will be three slices taken, of 100 lines or as defined by the user.
use strict;
use warnings;
use Readonly;
#figures out the input file or requests an input while returning the line
#of input, it also asks for an output file
sub call_file {
#If this is called with a parameter it will be with the path and file as
#the only parameter. This will then parse it and go to that file.
my ($path, $input_file);
if (defined($ARGV[0]) && ($ARGV[0] =~ /(.*\\)(.*)$/)) {
$path = $1;
$input_file = $2;
}
else {
print "I am ASSUMING that this .exe is in the same dir as the file\n";
print "that you want to process.\n";
print "Enter the file name you wish to correct: ";
chomp ($input_file = <>);
die "\n\nDo I look like a mind-reader?"
," What is the bloody extention?\n$!"
if $input_file !~ /.+\.\w{2,4}$/;
}
chdir $path if defined $path;
open INPUT, '<', "$input_file" or die "Can't open $input_file: $!";
print "Enter the name of the output file: ";
chomp (my $output_file = <>);
die "\n\nDo I look like a mind-reader? What is the bloody extention?\n$!"
if $output_file !~ /.+\.\w{2,4}$/;
open OUTPUT, '>', $output_file;
}
call_file;
my %EITlist;
open OUTPUT2 , '>', 'Error.log';
while () {
chomp (my $record = $_);
my ($EITnum, $begnum, $endnum) = split ',', $record;
my $beg_prefix = substr $begnum, 0, 4;
$begnum = substr $begnum, 4;
my $end_prefix = substr $endnum, 0, 4;
$endnum = substr $endnum, 4;
if ($beg_prefix ne $end_prefix) {
print OUTPUT2 " Beg Prefix: $beg_prefix End Prefix: $end_prefix => "
, "Prefix do not match at $.\n";
next;
}
elsif ($EITlist{$EITnum}->{$beg_prefix}) {
$EITlist{$EITnum}{$beg_prefix}->[0] = $begnum
if $begnum < $EITlist{$EITnum}{$beg_prefix}->[0];
$EITlist{$EITnum}{$beg_prefix}->[1] = $endnum
if $endnum > $EITlist{$EITnum}{$beg_prefix}->[1];
}
else {
$EITlist{$EITnum}{$beg_prefix}->[0] = $begnum;
$EITlist{$EITnum}{$beg_prefix}->[1] = $endnum;
}
}
close OUTPUT2;
close INPUT;
for my $EITnum (sort keys %EITlist) {
for my $prefix (sort keys %{$EITlist{$EITnum}}) {
print OUTPUT "$EITnum,$prefix$EITlist{$EITnum}{$prefix}->[0],"
,"$prefix$EITlist{$EITnum}{$prefix}->[1]\n";
}
}
close OUTPUT;
print "\n\n\nEnter to continue:\n";
<>