hello99hello
Programmer
Hello All,
I have a file with the following records:
Jasmin,Long ,23$45 ,1234A, MATLV, 0, 3
David ,Malow, 3328$,7765B, CRTLV, 2, 4
.
.
.
.
Susan ,Hagen, $8699 ,87564, VACLV, 0, 5
My aim is to have output file that has the following:
#The whole records in the file have to be put in an array.
#Also, columns 3,4, 5 and 6 has to be put in seperate arrays because the are too many #records. I am hoping to write foreach loop and for loop for the soltution.
Here is my effort:
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#The idea is to substitute meaningful values for column 5 based on the value of column #3. However because there are so many different values in column 3 (please note the $ #sign that requires an escape character, help so that it is not interpreted as variable.) that #calls for different values in column 5. I am thinking of putting them (columns 3 and 5) #in separate arrays. Please advise the best way to do this just so I don’t have to hard-code #every values like below.
if ($array[2] eq "23$45") {
$array[4] = "MATERNITY LEAVE";
#Also, if column 6 is greater than zero use the value in the column else use the value in #column 7 whichever is greater than zero.
if ($array[5] == 0 ) {
$array[5] = $array[6]
else
$array[5] = $array[5]
}
Here is sample output
Jasmin,Long ,23$45 ,1234A, MATERNITY LEAVE, 3, 3
David ,Malow, 3328$,7765B, COURT DUTY LEAVE, 2, 4
.
.
.
.
Susan ,Hagen, $8699 ,87564, VACATION LEAVE, 5, 5
I have a file with the following records:
Jasmin,Long ,23$45 ,1234A, MATLV, 0, 3
David ,Malow, 3328$,7765B, CRTLV, 2, 4
.
.
.
.
Susan ,Hagen, $8699 ,87564, VACLV, 0, 5
My aim is to have output file that has the following:
#The whole records in the file have to be put in an array.
#Also, columns 3,4, 5 and 6 has to be put in seperate arrays because the are too many #records. I am hoping to write foreach loop and for loop for the soltution.
Here is my effort:
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#The idea is to substitute meaningful values for column 5 based on the value of column #3. However because there are so many different values in column 3 (please note the $ #sign that requires an escape character, help so that it is not interpreted as variable.) that #calls for different values in column 5. I am thinking of putting them (columns 3 and 5) #in separate arrays. Please advise the best way to do this just so I don’t have to hard-code #every values like below.
if ($array[2] eq "23$45") {
$array[4] = "MATERNITY LEAVE";
#Also, if column 6 is greater than zero use the value in the column else use the value in #column 7 whichever is greater than zero.
if ($array[5] == 0 ) {
$array[5] = $array[6]
else
$array[5] = $array[5]
}
Here is sample output
Jasmin,Long ,23$45 ,1234A, MATERNITY LEAVE, 3, 3
David ,Malow, 3328$,7765B, COURT DUTY LEAVE, 2, 4
.
.
.
.
Susan ,Hagen, $8699 ,87564, VACATION LEAVE, 5, 5