hello99hello
Programmer
I have an input file (pers_in.txt) with the following records:
2067,Janice,LIFE,Y -------record 1
2067,Janice,MSP,Y -------record 2
2045,Enry,LIFE,Y -------record 3
2045,Enry,OPT,N -------record 4
2345, Louis,MSP,N -------record 5
2345, Louis,OPT,N -------record 6
My purpose is to put it in array, manipulate each record and generate ouput file.
Here is my effort:
#check input file
$input_file = "pers_in.txt";
(-e $input_file) || die ("input file does not exist \n") ;
open(INPUT, "$input_file") || die ("could not open infile\n");
open(OUTPUT, ">$output_file") || die ("could not open outfile \n") ;
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#if there is 'Y' in the fourth element, insert duplicate record only once for each first element (once for 2067 and once for 2045) let us call this record 1d.
#lastly change the values of the second and third element of only the newly added record from Janice to Janice2 and LIFE to EHP LIFE while leaving other elements the same .
# can this be done in perl or it would be eaiser in SQL?
if ($array[3] = "Y"){
#Here is where I am stumped, any help would be really appreciated.
}
}
#print the output
$new_record = join ',', @array;
print OUTPUT "$new_record\n";
}
close (INPUT) ;
close (OUTPUT) ;
The sample output record file could look like:
2067,Janice,LIFE,Y -------record 1
2067,Janice2,EHP LIFE,Y -------record 1d
2067,Janice,MSP,Y -------record 2
2045,Enry,LIFE,Y -------record 3
2045,Enry2, EHP LIFE,Y -------record 3d
2045,Enry,OPT,N -------record 4
2345, Louis,MSP,N -------record 5
2345, Louis,OPT,N -------record 6
2067,Janice,LIFE,Y -------record 1
2067,Janice,MSP,Y -------record 2
2045,Enry,LIFE,Y -------record 3
2045,Enry,OPT,N -------record 4
2345, Louis,MSP,N -------record 5
2345, Louis,OPT,N -------record 6
My purpose is to put it in array, manipulate each record and generate ouput file.
Here is my effort:
#check input file
$input_file = "pers_in.txt";
(-e $input_file) || die ("input file does not exist \n") ;
open(INPUT, "$input_file") || die ("could not open infile\n");
open(OUTPUT, ">$output_file") || die ("could not open outfile \n") ;
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#if there is 'Y' in the fourth element, insert duplicate record only once for each first element (once for 2067 and once for 2045) let us call this record 1d.
#lastly change the values of the second and third element of only the newly added record from Janice to Janice2 and LIFE to EHP LIFE while leaving other elements the same .
# can this be done in perl or it would be eaiser in SQL?
if ($array[3] = "Y"){
#Here is where I am stumped, any help would be really appreciated.
}
}
#print the output
$new_record = join ',', @array;
print OUTPUT "$new_record\n";
}
close (INPUT) ;
close (OUTPUT) ;
The sample output record file could look like:
2067,Janice,LIFE,Y -------record 1
2067,Janice2,EHP LIFE,Y -------record 1d
2067,Janice,MSP,Y -------record 2
2045,Enry,LIFE,Y -------record 3
2045,Enry2, EHP LIFE,Y -------record 3d
2045,Enry,OPT,N -------record 4
2345, Louis,MSP,N -------record 5
2345, Louis,OPT,N -------record 6