Note: there could be multiple lines that begin w/QTY, TED and OTI. What I did was write a PERL script that inputs the file, creates an array of six items (for those that don't have six items it fills the empty ones in as blank), it then goes and counts how many of the first item appears. Here is the code I have written thus far (i know it's not the most efficient but it works!)HDR,831 Reconciliation,200008081441EST BGN,11,000000158,20000808,10520000 OTI,GH,BT,WEDI620000802,159 AMT,2,231644 AMT,BT,231644 AMT,NP,0 QTY,46,10 QTY,53,0 QTY,54,10 QTY,55,0 TED,ZZZ,BATCH AWAITING 831 OTI,TR,CK,0021000095,159,000101416 TED,ZZZ,MOD CHECK ON RDFI-ID FAILED
What I would like to be able to do is go in and output the data in any format. For example, to print out the second and third items of all the QTY's and print the third item in the HDR and the fourth and fifth of all of the OTIs. I've been looking at associative array's/hashes and everything else and I really don't know what to use. Any suggestions?#!/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 = <FILE>; #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 bu +t 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, $thir +d) } $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);
In reply to Creating the right type of array... by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |