Problem with Mail merge in perl
This could be a simple problem for the perl experts
I am trying mail merge in perl
The header file is head1 which is as under
,,ACTION,TRANS_ID,,TBL,ForwardDeals_Id,DealStatus,InputMode,CaptureDate,TradeDate,Users_Id,Users_Id_ Last,Folders_Id,Purposes_Id,TypeOfEvent,BlockNumber,TypeOfInstr_Id,Comments,Pairs_Id,Amount1,Amount2 ,
The file containing the values is csv which is as under
,,"INS",973795,,ForwardDeals,883797,V,I,"04/05/2009,04/05/2009,63768,0,63761,61987,K,887591,58935,"649978-booked,52006,-475000.0,23607500.0
,,"INS",973796,,ForwardDeals,883798,V,I,"04/05/2009,04/05/2009,63768,0,63761,61987,K,887592,58935,"649978-booked,52006,-575000.0,33607500.0
,,"INS",973797,,ForwardDeals,883799,V,I,"04/05/2009,04/05/2009,63768,0,63761,61987,K,887593,58935,"649978-booked,52006,-478000.0,23608500.0
The perl script is to merge the head and csv is
#!/usr/bin/perl
while ($f = (head1)) {
open (FH, $f) or die "Can't open $f : $!";
while (<FH>) {
chomp;
push @contents, $_;
@contents = split(/,/);
}
while (<>) {
chop() ;
push @values, $_;
@values = split(/,/);
$size = @values;
}
for ($i = 0 ;$i < $size ; $i++) {
printf "$contents[$i] $values[$i] \n" ;
}
}
I am able to get the merge for 1st row of the csv file and the head1 as under by executing
perl mail_merge.pl csv
ACTION "INS"
TRANS_ID 973795
TBL ForwardDeals
ForwardDeals_Id 883797
DealStatus V
InputMode I
CaptureDate "04/05/2009
TradeDate 04/05/2009
Users_Id 63768
Users_Id_Last 0
Folders_Id 63761
Purposes_Id 61987
TypeOfEvent K
BlockNumber 887591
TypeOfInstr_Id 58935
Comments "649978-booked
Pairs_Id 52006
Amount1 -475000.0
Amount2 23607500.0
I am not able to merge the head with the subsequent rows of csv .The desired output would be
ACTION "INS"
TRANS_ID 973795
TBL ForwardDeals
ForwardDeals_Id 883797
DealStatus V
InputMode I
CaptureDate "04/05/2009
TradeDate 04/05/2009
Users_Id 63768
Users_Id_Last 0
Folders_Id 63761
Purposes_Id 61987
TypeOfEvent K
BlockNumber 887591
TypeOfInstr_Id 58935
Comments "649978-booked
Pairs_Id 52006
Amount1 -475000.0
Amount2 23607500.0
ACTION "INS"
TRANS_ID 973796
TBL ForwardDeals
ForwardDeals_Id 883798
DealStatus V
InputMode I
CaptureDate "04/05/2009
TradeDate 04/05/2009
Users_Id 63768
Users_Id_Last 0
Folders_Id 63761
Purposes_Id 61987
TypeOfEvent K
BlockNumber 887592
TypeOfInstr_Id 58935
Comments "649978-booked
Pairs_Id 52006
Amount1 -575000.0
Amount2 33607500.0
Please guide ,Thanks in advance