
jared.collier
Novice
Jul 1, 2009, 10:41 AM
Post #1 of 3
(1094 views)
|
|
Unexpected Output
|
Can't Post
|
|
I'm having trouble extracting information from a series of documents. The snippet of code I've included is meant to take the input file and store the different sections in an array (although the code to store in the array is not yet present, instead I've inserted a test to find out what $1 returns). I'm calling my program with MRN as a parameter. open(CURRENT_FILE, $currentFile) || die ("Could not open the input file $currentFile - $!"); if ($ARGV[0] eq 'MRN' || $ARGV[0] eq 'DOB' || $ARGV[0] eq 'Gender' || $ARGV[0] eq 'SSN' || $ARGV[0] eq 'Account') { while (<CURRENT_FILE>) { if ($_ =~ /(PID.*)$/) { print "\n$1\n"; }else { print "\nERROR\n"; } } }elsif.......... In this case, I'm trying to pull just the PID section of a file which I'll then split and extract the sub-field information. Below is a scrubbed example of an input file: MSH|^~\&|TESTADT|HHH|AAA-ADT|myCompany|200003470212||ADT^A08|ACSC-ADT.1.355132|P|2.7 PID|1||M113928|M1111|LASTNAME^FIRSTNAME^E||11112229|M||||||||||V321319293949596960 PV1|1|I|LOCATION^1^A|||||||MED/SURG||||||||IN||||||||||||||||||||||||||200000000011|212312312306 PV2|||||||||||||||||||||||||DIS in this particular case, the output looks like: PV1|1|I|LOCATION^1^A|||||||MED/SURG||||||||IN||||||||||||||||||||||||||200000000011|212312312306 PV2|||||||||||||||||||||||||DIS While I would like to extract: PID|1||M113928|M1111|LASTNAME^FIRSTNAME^E||11112229|M||||||||||V321319293949596960 Thanks in advance for the insight. I have a feeling it has something to do with carriage returns and new line special characters (I tried replacing the $ in the regex with \r\n but had no luck). It should be noted that when I open the target document in notepad, the new line characters appear as boxes (almost like []).
|