Richard J. Moyer III wrote at Wed, 29 May 2002 02:39:45 +0200:

> Hello all,
> 
> I have a form that activates a cgi script that scans a flat-file *.csv file, matches 
>on a unique
> identifier, identifies the line that contains the identifier, and pushes the 
>separated values of
> that line into an array.
> 
> I want to pass those values into another (second) cgi script, but I don't know how.
> 
> I made the original script display the values of the line in "text" input boxes in a 
>web page the
> original cgi script created after finding the correct line.  This essentially 
>creates a new form
> that *theoretically* you should be able to parse with a new script.  However, when I 
>push submit,
> the form runs the ORIGINAL script and passes all the data from the new form into the 
>URL (i.e.
> "ref.cgi?n0=052802151217&n1=2...").
> 
> Who do I fix this.
> 

Sorry, I can't give you the answer you hoped.
The script is still to complex for me.
But I hope I can give you some advices to write the script
more "Perlish".

> 
> 
> 01 #!/usr/bin/perl

use strict;

With a cgi script, 
you should also check for tainted data
and to give warnings:
#!/usr/bin/perl -wT


> 02
> 03 print "Content-type:text/html\n\n";

You should have a look for the CGI module.
Definitly.

> 04
> 05 read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> 06 @pairs = split(/&/, $buffer);
> 07 foreach $pair (@pairs) {
> 08      ($name, $value) = split(/=/, $pair);
> 09      $value =~ tr/+/ /;
> 10      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; 11      
>$FORM{$name} =
> $value;
> 12 }
> 13
> 14 $reference = $FORM{'ref'};
> 15
> 16 #----------------------------------------------------------- 17 #---- COMPARE 
>REFERENCE NUMBER
> TO DATA
> 18#----------------------------------------------------------- 19 open (DATA, 
>"<../data/data.csv")
> or die &error; 20 while ($line = <DATA>) {
> 21     if ($line =~ /($reference)/){
> 22      push @newdata, $line;
> 23     }
> 24 }

my @newdata = grep {/$reference/} (<DATA>);

> 25 close (numbers);
> 26
> 27 #----------------------------------------------------------- 18 #--- OK -- OK -- 
>OK -- OK -- OK
> -- OK --
> 29 #----------------------------------------------------------- 
> 30 $begin=0; 31 for($i=0; $i < length $newdata[$#newdata]; $i++) { 
> 32      if ((substr $newdata[$#newdata], $i, 1) eq "," or
>             (substr $newdata[$#newdata], $i, 1) eq "\n") { 
> 33              push @tokens, (substr
                                 $newdata[$#newdata], $begin, $i-$begin); 34 $begin = 
$i+1;
> 35      }
> 36 }

Well, the substring seems to be a little bit crazy :-)
$i depends on the length of the array.
$begin depends on the numbers of entries starting with a ',' or '\n'

You use only $newdata[$#newdata],
that means you only use the last element of the array.

It's unrare the both has something in common
with the length of the strings that are saved in the array.

However the condition is simplier written as
if ($newdata[$#newdata] =~ /^[\,\n]/) { ... }

> 37 if ($tokens[1] >= "1"){
> 38     $episode = $tokens[1];
> 39     $nextepisode = $episode + 1;
> 40
> 41 print <<EndOfHTML;

You should have a look to the template modules:
http://search.cpan.org/search?mode=module&query=template

> 42 <html>
> 43 <head>
> 44 <title>CHUG Output</title>
> 45 </head>
> 46 <body bgcolor=#cc6600>
> 47 <table width="100%" cellspacing=7 cellpadding=0 border=1 bgcolor=#ffffff> 48   
><tr> 49     <td
> align="left" valign="top" colspan="2"><p class="text">What would you like to do 
>now?</td>
> 50   </tr>
> 51   <tr>
> 52     <td align="left" valign="top" width="50%">
> 53      <table width="100%" cellspacing=7 cellpadding=0 border=1 bgcolor=#ffdddd> 54 
>       <tr>
> 55          <td>
> 56          <form name="reprint" action="reprint.cgi" method="post"> 57          
><input
> type="text" name="n0" value="$tokens[0]"> REFERENCE NUMBER<br> 58          <input 
>type="text"

You read in an array of reference numbers,
if i understand correctly.
Which of them is the REFERENCE NUMBER you want.

> name="n5" value="$tokens[3]"> Sex</br> 59          <input type="text" name="n6"
> value="$tokens[5]"> Weight</br> 60          <input type="text" name="n7" 
>value="$tokens[58]">

Wow, the tokens have the index numbers 0, 3, 5, 58, 70.
These are really magic numbers.
But them into constant variables expressing what the say like.
Take a look to the constant pragma and the enum - module from the cpan

> percent less</br> 61          <input type="text" name="n11" value="$tokens[70]"> 
>Negcon</br> 62   
>       <input type="submit" name="submit"> 63          </form>
> 64          </td>
> 65          </td>
> 66        </tr>
> 67      </table>
> 68      </form>
> 69    </td>
> 70 </tr>
> 71</table>
> 72 </body>
> 73 </html>
> 74 EndOfHTML
> 75 exit;
> 76 }
 

Best Wishes,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to