title: Pass block of text from webpage to perl script and then back to web
body: <p>I am trying to do the following. </p>
  
  <p>Take a block of text that a user inputs in a TEXTAREA FORM from a website and pass it to a perl/cgi script that adds the line number before each line.  So for example:</p>
  
  <pre><code>diet coke
  potato chips
  gelato
  </code></pre>
  
  <p>would become</p>
  
  <pre><code>1 diet coke
  2 potato chips
  3 gelato
  </code></pre>
  
  <p>I know how to pass a single value or a bunch of values to a perl script, but when I try to do a foreach (@array) to add a line number it doesn't work.  Wondering how to do this.</p>
  
  <p>My html file is</p>
  
  <pre><code>&lt;HTML&gt;
  &lt;BODY&gt;
  
  &lt;FORM ACTION="/cgi-bin/splitfoods.pl"&gt;
    &lt;P&gt;What did you eat today? &lt;BR&gt;&lt;TEXTAREA NAME="value" ID="value" style="width:900px;height\
  :700px;background-color:#FFF8DC;font-size:20px"&gt;
      &lt;/TEXTAREA&gt;
  
  &lt;P&gt;&lt;INPUT TYPE="SUBMIT" VALUE="Submit"&gt;
  &lt;/FORM&gt;
  
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  
  <p>and the cgi file is (from matthewh)</p>
  
  <pre><code>#!/usr/bin/perl
  
  use CGI;
  use CGI qw(:standard);
  
  
  $query = new CGI;
  
  @foods = split('\n',$query-&gt;param("value"));
  
  
  # -- HTML STUFF --
  print header;
  print start_html;
  for($i=1; $i&lt;=@foods; $i++) {
      print "$i @foods[$i-1]";
      print "&lt;br&gt;";
  }
  print end_html;
  </code></pre>
  
  <p>request looks like</p>
  
  <pre><code>cgi-bin/splitfoods.pl?value=diet+coke%0D%0Apotato+chips%0D%0Agelato
  </code></pre>
  
  <p>Thanks</p>