in reply to [Study]: Searching for square roots
sub middle ($$) { my ( $a, $b ) = ( shift, shift ); return ($a + $b) / 2 }
Don't pass parameters like that, it's confusing: which shift gets executed first? I'd either use it if only one is involved at a time, and possibly if I have to use the rest of @_ as a whole, or stick with:
my ($n,$m)=@_;
(I tend not to use $a and $b as general purpose variables even when they wouldn't be error prone because... their use is potentially error prone.)
It's a commonly recommended style to put a semicolon on the last line too.
Oh, and there's no need to use prototypes. Actually many people deprecate them. I find them useful for code and autorefs, but other than that they don't buy you much.
print "SQRT 16:\n", &sqrt( 16 ), $/, $/;
&-form of sub call is now obsolete and most likely not to do what you want. Read more about this in perldoc perlsub.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: [Study]: Searching for square roots
by duff (Parson) on Nov 14, 2006 at 17:51 UTC | |
by blazar (Canon) on Nov 15, 2006 at 09:39 UTC | |
Re^2: [Study]: Searching for square roots
by revdiablo (Prior) on Nov 14, 2006 at 23:48 UTC | |
by blazar (Canon) on Nov 15, 2006 at 09:48 UTC | |
Re^2: [Study]: Searching for square roots
by GrandFather (Saint) on Nov 14, 2006 at 17:41 UTC | |
by blazar (Canon) on Nov 15, 2006 at 09:37 UTC | |
Re^2: [Study]: Searching for square roots
by pemungkah (Priest) on Nov 15, 2006 at 21:19 UTC |