MinnisotaFreezing
Programmer
Hi, sorry for the very simple question, but I can't seem to get anywhere with it. Here goes:
I want to read a small text file with CGI and output the array to a JavaScript array.
I have this:
#!/usr/bin/perl
open(INFO, "names_file.txt" # Open db for reading and display
@array=<INFO>;
close (INFO);
great, now the tutorial I read shows how to print to screen by parsing the array and such. But I don't want to print to screen, I want to load the data from @array into a JavaScript array, and then parse out with Java because I don't want the data displayed all at once. I wan't the CGI script to run, get all the data to memory(Its small)then access the data 1 at a time.
Some psudo-code:
//My Script called read.pl
#!/usr/bin/perl
open(INFO, "names_file.txt" # Open db for reading and display
@array=<INFO>;
close (INFO);
return @array;
//My Page
<script Language="JavaScript">
var Source = new Array
Source = /cgi-local/axs/read.pl
Maybe a better way would be to dump the output of the CGI into a hidden form, and then read that into my array, but I can't even do that.
I realize this not the right way to do all this, but my page is done with the exception of this problem, and it is in JavaScript. I've looked on the web for a long time at CGI tutorials, but they all show output to screen. I understand CGI runs all at once, and that trying to catch out put 1 line at a time probably won't work. If I could only get a pointer to @array, but no.
Anyway, any help is of course appriciated.
I want to read a small text file with CGI and output the array to a JavaScript array.
I have this:
#!/usr/bin/perl
open(INFO, "names_file.txt" # Open db for reading and display
@array=<INFO>;
close (INFO);
great, now the tutorial I read shows how to print to screen by parsing the array and such. But I don't want to print to screen, I want to load the data from @array into a JavaScript array, and then parse out with Java because I don't want the data displayed all at once. I wan't the CGI script to run, get all the data to memory(Its small)then access the data 1 at a time.
Some psudo-code:
//My Script called read.pl
#!/usr/bin/perl
open(INFO, "names_file.txt" # Open db for reading and display
@array=<INFO>;
close (INFO);
return @array;
//My Page
<script Language="JavaScript">
var Source = new Array
Source = /cgi-local/axs/read.pl
Maybe a better way would be to dump the output of the CGI into a hidden form, and then read that into my array, but I can't even do that.
I realize this not the right way to do all this, but my page is done with the exception of this problem, and it is in JavaScript. I've looked on the web for a long time at CGI tutorials, but they all show output to screen. I understand CGI runs all at once, and that trying to catch out put 1 line at a time probably won't work. If I could only get a pointer to @array, but no.
Anyway, any help is of course appriciated.