http://www.perlmonks.org?node_id=1140122

ash1351 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am taking backend perl variables and using it at the front end for display. Here is the code. head1 and head2 are the header names taken from perl script. I use that and display those headers of grid on webpage.

var headname1= "@head1"; var headname2= "@head2";
Now, if there are 100 headers, i would have to assign variables 100 times separately. so its better to make it dynamic. Taking values from backend and assigning it to javascript variable. This task will be dynamic. Here is my attempted code for that. I hav taken all the headers from backend and assigned it to line_array. @line_arry is the name of that array. If i do @line_arry[0] and so on. appropriate values will be displyaed.
var headname=[]; for(var i=0;i<total_columns;i++) { headname[i+1]= "@line_arry[(i)]"; }
This code doesnot work. It displays only the first column. i.e.
headname[1] = "Order"; headname[2] = "Order";
Order is the name of the first header. In headname2, header of second column should be displayed. but it still displays "Order" If i write the below code, it displays first and second header.
headname[i+1]= "@line_arry[(0)]"; headname[i+1]= "@line_arry[(1)]"; "@line_arry[i]" doesnt work whereas "@line_arry[0], @line_arry[1] works.
Can anyone suggeest why it is not performing looping action using variable i