Ideally, the length field tells the parsing program how long the record is. The file is usually broken into its seperate records and put into MQ/Series to be sent to the database.
There are a few things that will cause the file to be rejected. One is, it reads a record (or what it thinks is a record) and then tries to read the next three characters, expecting the next record ID. If they are there, the file is put aside for us to fix.
Now... given what you are saying... will this work like I expect it to?
$RID = "MEH|MED|MMD|MMS|CR1|FR1";
while(<$dpf>) {
while(m/($RID)(....)(.*)($RID)/g) {
$RecordID = $1; $RecordLen = $2; $RecordData = $3;
if (len($RecordData) != $RecordLen) {
#ERROR: Record is wrong length
}
}
}
What I am expecting is: it will step through the file (an example given below) over and over again, pulling each record into $RecordData. Do I need to use \G to get to continue where it left off? Do I need to do anything special for the last record in the file? Why did you use
[^$TLI]+?
-Travis
PS: Example file:
MEH0016BUNCHODATA123456MED0019BUNCHMOREDATA456789MED0018MOREDATAAGAIN4
+4568
v0.2: changed
while($dpf) to
while(<$dpf>). Which brings us back to reading the file into $_. Thank, Tye.