Assuming that the form has input fields named:
val-i-j, where i and j are subscripts of the
coefficients in the matrix, the following code puts all
the information in a 2D array called @matrix. The
specialty of this snippet is that is works with imaginary
numbers as well as real numberr. (Both i and j
can be used to refer to sqrt(-1) )
use Math::Complex;
# Get the data, put it in hash called: %form
if($ENV{'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else{
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
foreach $pair (@pairs){
local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$form{$name} = $value;
}
for($i=1;$i<($var_no+1);$i+=1){
for($j=1;$j<=($var_no+1);$j+=1){
$deger = "val-".$i."-".$j;
@kompleksler = split(/\+/,$form{$deger});
$imaginary = 0;
$real = 0;
foreach $complex (@kompleksler){
if($complex =~ m/(i|j)/){
$imaginary += $complex;
}
else{
$real += $complex;
}
}
$matrix[$i][$j] = cplx($real, $imaginary);
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.