in reply to Getting a Human Readable Report from a data file
In any case, the solution would depend on how easy it is to identify boundaries between consecutive records, given that each record consists of multiple lines with rather intricate white-space formatting. The example suggests that each new record begins with this sort of pattern, which can be used to capture this part of the info for the report:
and that the "SNBX" and "TRX" records always follow line-initial whitespace, so they can be captured as follows:/^(BCG-\d+)/ # i.e. line-initial "BCG-" followed by digits
If those assumptions hold, then the logic could go something like this (not tested):/^\s+(SNBX\S+)/ /^\s+(TRX-\d+)\s+\S+\s+BL-TRX/
That would probably need some tweaking to get the column alignments right -- you could try the FORMAT mechanism (which I never really got the hang of) or the printf function (which I've been hooked on since cutting my teeth in C years ago).print "BCG LOCATION TRX STATUS\n"; print "---------------------------------\n"; while (<>) { if (/^(BCG-\d+)/) { # start of record $recid = $1; $loc = $trx = $stat = ""; } elsif (/^\s+(SNB\S+)/) { $loc = $1; } elsif (/^\s+(TRX\S+)\s+\S+\s+(BL-TRX)/) { print "$recid $loc $1 $2\n"; } }
|
|---|