Thanks... I guess I was just doing something stupid. My data was in a single column, so I tried this...Thanks... I guess I was just doing something stupid. My data was in a single column, so I tried this...
use Math::Complex;
my @array = qw(
1+i
-1+i
-1-i
1-i
3
3*i
-3
-3*i
1+2*i
2+i
-1+2*i
.
.
.
And, it doesn't work with the qw or without the qw. Without the qw I got zillions of errors, with the qw the Re portion was the whole thing and the there were no imaginary portions. I guess the complex constructor would not be called if the array element is considered to be a string...
So, I just change the delimiter for my data from a new line to a comma-space, like you have, and it now works...
use strict;
use warnings;
use Math::Complex;
my @list = (1+i, -1+i, -1-i, 1-i, 3, 3*i, -3, -3*i, 1+2*i, 2+i, -1+2*i, -2+i, -2-i, -1-2*i, 1-2*i, 2-i, 7, 7*i, -7, -7*i, 11, 11*i, -11, -11*i, 2+3*i, 3+2*i, -2+3*i, -3+2*i, -2-3*i, -3-2*i, 2-3*i, 3-2*i, 1+4*i, 4+i, -1+4*i, -4+i, -1-4*i, -4-i, 1-4*i, 4-i, 19, 19*i, -19, -19*i, 23, 23*i, -23, -23*i, 2+5*i, 5+2*i, -2+5*i, -5+2*i, -2-5*i, -5-2*i, 2-5*i, 5-2*i, 31, 31*i, -31, -31*i, 1+6*i, 6+i, -1+6*i, -6+i, -1-6*i, -6-i, 1-6*i, 6-i, 4+5*i, 5+4*i, -4+5*i, -5+4*i, -4-5*i, -5-4*i, 4-5*i, 5-4*i, 43, 43*i, -43, -43*i, 47, 47*i, -47, -47*i);
print "List: @list\n";
foreach (@list) {
print "$_\t-> re=", Re( $_ ), ", im=", Im( $_ ), "\n";
}
Thanks all of you for the help.
I noticed that some of you are using Perl 6... I think 'say' is Perl 6? I'm using Perl 5 with Padre on DWIM Perl on Windows. My experience with Perl on Windows is difficult... Active Perl is a pain because so many of the Perl modules that I want can't be had, or cost a lot of money for a subscription. And Strawberry Perl's a pain when someone who's NOT a Perl Monk has to figure out how to use a module that you've downloaded from CPAN. So, DWIM Perl is easier for some of these things, and it comes with Padre. However, it's Perl 5... is there a relatively easy way a NON-Perl Monk can upgrade the Perl that DWIM Perl and Padre are using to Perl 6?
Thanks again, Paul
In reply to Re^2: array of complex numbers
by pmccarthy
in thread array of complex numbers
by pmccarthy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |