in reply to Obtain matrix info

So let me take a whack at this, and also solve a few bugs:
use Math::Complex; use CGI qw(param); for my $i (1..$varno) { for my $j (1..$varno) { next unless my $val = param("val-$i-$j"); if (my($re, $im) = $val =~ /(.*)([-+].*)[ij]/) { $matrix[$i][$j] = cplx($re, $im); } else { $matrix[$i][$j] = cplx($val, 0); } } }
I still don't entirely like the complex parsing. But at least now I can say 5-3j, unlike your code where you had to say 5+-3j. Oddly enough, I don't know why Math::Complex doesn't have an input parser. It should!

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: Obtain matrix info
by sinan (Sexton) on Jul 30, 2000 at 15:07 UTC
    Thanks for the fix!!

    Well, it seems that I could use
    $matrix[$][$j] = eval( param("val-$i-$j") );
    But I did not want to use eval();

    Normally, $C = 5+4j works fine. So under normal circumstances, you don't need a parser... I browsed through the man page, but I did not find anything like that.