#!/usr/local/bin/perl5 #PERL Script #1. Input the text file containing the formatted info open (FILE,"<824.txt") || die "Can't open file $!"; @lines = ; #initialize the counters $HDRcount = 0; $BGNcount = 0; $OTIcount = 0; $AMTcount = 0; $QTYcount = 0; $TEDcount = 0; #Create the main array foreach (@lines) { chop; ($key, $first, $second, $third, $fourth, $fifth) = (split(/,/)); $key = "" if !defined($key); #I know this part isn't needed but i'd rather not get errors $first = "" if !defined($first); $second = "" if !defined($second); $third = "" if !defined($third); $fourth = "" if !defined($fourth); $fifth = "" if !defined($fifth); $sixth = "" if !defined($sixth); print("Key=$key 1=$first 2=$second 3=$third 4=$fourth 5=$fifth\n"); #Search through firstElementArray counting up each instance of # HDR, BGN, OTI, AMT, QTY, TED if ($key eq "HDR") { $HDRcount++; #create an array here, similiar to @HDR($first, $second, $third) } $BGNcount++ if ($key eq "BGN"); $OTIcount++ if ($key eq "OTI"); $AMTcount++ if ($key eq "AMT"); $QTYcount++ if ($key eq "QTY"); $TEDcount++ if ($key eq "TED"); } #test to make sure it works print("HRD=$HDRcount BGN=$BGNcount OTI=$OTIcount AMT=$AMTcount QTY=$QTYcount TED=$TEDcount\n"); close(FILE);