in reply to Weird Perl Rule I'm Probably Not Following
Cleaned up the code some, I know many people learn by example so here is how you might improve the code. Declare all variables you want to use with "my", especialy inside of the sub. Grab arguments to the sub with shift (this is iffy and probably good arguments both ways. The important thing it to be consistent.) Indent code inside a sub so that you can tell the scope of that sub (where variables declared inside it with my will retain there uniqness for lack of a better workd.)
sub argComplex { my $value1 = shift; # shift along acts on @_ so its the same as @ +_[0]; my @construct = &constructComplex($value1); my $real1 = @construct[0]; my $complex1 = @construct[2]; return atan2($complex1, $real1); } my $real1; my $z; $real1 = 1; $z = 1 + i; print $real1 * argComplex($z);
P.S. It is easier to help when you provide a working example. In this case people spoted the error but if you break the problem down into a working example to show peopl, 90% of the time you will find your error before posting! ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Weird Perl Rule I'm Probably Not Following
by nedals (Deacon) on Oct 14, 2005 at 23:16 UTC | |
by eric256 (Parson) on Oct 15, 2005 at 04:44 UTC |