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! ;)


___________
Eric Hodges

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
    my $value1 = shift; # shift along acts on @_ so its the same as @_[0];

    Not really.
    shift will remove the first element from @_
    @_[0] leaves it in place

      Sorry you took that a little literaly. I meant that it filled the same position as @_[0] did in his code. Which IS true. I probably should have made that clearer.


      ___________
      Eric Hodges