
obrien135
Novice
Nov 23, 2012, 5:42 AM
Post #1 of 5
(23008 views)
|
Hello, The question I have today is: I have been writing data into a file from an html form where the action is performed by selecting a submit button. I thought I would get seperate entries into the file but when I try to read them out into an array it performs as though it is one big string. I am wondering why this is happening and how I can getthem to be seperate elements in an array. Thank you. George #!/usr/bin/perl print "Content-type: text/html\n\n"; $n = 0; $k = 0; @array = (); $Lineout = ""; $TheReq = ""; if($ENV{"REQUEST_METHOD"} eq 'GET'){$TheReq = $ENV{"QUERY_STRING"}} else {read(STDIN, $TheReq, $ENV{"CONTENT_LENGTH"})} #print $TheReq; open(OUT, '>>file.txt') or die "Couldn't open file.txt file, \n"; #select(OUT); printf OUT "<HTML>%s</HTML>", $TheReq; #select(STDOUT); #print("hello world2"); close(OUT); $TheReq = ""; #print("hello world2"); open(B, '<file.txt'); $n = -1; while (<B>) { chomp; $n++; $Lineout = $_; @array[$n] = $Lineout; #printf ("<HTML><P>%d<BR></P></HTML>", $n); #print $n; } # print("hello world 2.5"); #print("hello world3.5"); close (B); #print("hello world6"); #$k = $n; $k = 0; #printf ("<HTML><P>%d<BR></P></HTML>", $n); #while($k >= 0) #{ #$k -= 1 #printf ("<HTML><P>%s<BR></P></HTML>", @array[$k]); #} for($k == $n; $k >= 0; $k--) { printf ("<HTML><P><BR>%s<BR></P></HTML>", @array[$k]); #printf ("<HTML><P>%d<BR></P></HTML>", $k); } #print("hello world6.5");
|