Re: why Perl complaints my script
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 28 Sep 2006 10:52:25 -0700
Chen Li wrote:
I write a small script for permutation. When I use
version 1) Perl always complaint it although I get the
result. If I use version 2) it never says a word about
it. Any comments?
The warning message is pretty clear, IMHO....
for ($k; $k>=1;$k--) {$result*=$n--;}#line 15
return $result;
}
Useless use of private variable in void context at
fac1.pl line 15.
Right. You're uselessly using a variable in void context.
Specifically, the $k. Why? What do you think the first part of that
is doing? What effect do thinking "$k;" has? None. That's why it's
"useless".
To remove the warning, just get rid of the initialization:
for ( ; $k >= 1; $k-- ) {
$result *= $n--;
}
But that's also remarkably non-Perlish. I would change to:
while ($k >= 1) {
$result *= $n--;
$k--;
}
By the way, why do you refuse to use whitespace? Why is everything all
bunched together? Isn't it easier to read when you separate statements
on multiple lines and surround operators with whitespace characters?
Paul Lalli
.
- References:
- why Perl complaints my script
- From: Chen Li
- why Perl complaints my script
- Prev by Date: Re: cgi script
- Next by Date: Re: hash slices
- Previous by thread: Re: why Perl complaints my script
- Next by thread: hash slices
- Index(es):
Relevant Pages
|
|