Hi so what I'nm ultimately trying to do here is get user input from a textarea in a form ( method POST) and basically read it line by line and store the lines in a kind of state variable or counter until a blank line is hit and the value of the state variable is pushed onto an array as one element. The state variable is then reset after this and the process continues until all the input is read. In visual terms, this is what it is supposed to do. Example of user input: some example user input to show something with hello world lorem ipsum * I want the program to read those two first lines and push them into one array element when the program sees that there is a blank line beneath them. Same thing applies with the line "hello world lorem ipsum". This is what I have so far. I had tried a foreach loop at first but it didn't work either

#!/usr/bin/perl use strict; use warnings; use CGI; my $CGI = new CGI(); sub main { print $CGI->header(); my @query = $CGI->param('query'); while(@query) { my $line = shift(@query); print "$line"; } #my $count = 0; #my @res; #foreach my $line(@query) { # if($line =~ /[A-Za-z0-9]/) { # push(@res, $line); # } elsif ($line =~ /^\s$/) { # $count++; # } #} print<<HTML; <html> <head> <style> textarea { resize: none; } </style> </head> <form action="rand.cgi" method="post"> <textarea name="query"></textarea> <input type="submit"/> </form> <p>Last submitted:<br><br><pre>@query</pre></p> </html> HTML } main();

In reply to How to read through form input line by line and categorize the information by JohnTabor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.