Re: why Perl complaints my script



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

.



Relevant Pages

  • Re: regexp question
    ... >> Would find 5 whitespace characters at the start of a line followed by ... > simplest regexp statement still looks like a monkey pounded on the ... If you were to do it in Perl: ... bclennox AT eos DOT ncsu DOT edu ...
    (comp.lang.perl.misc)
  • It seems that Win32::OLE::Variant doesnt work!
    ... use strict; ... Below is the warning message: ... I am using the following version of perl: ... Thy mean the lower boundary of the second dimension, ...
    (perl.beginners)
  • Re: Bundle::Apache compilation errors
    ... gunzip wrote: ... tried doing what the warning message says to do? ... Cocoa programming in Perl: http://camelbones.sourceforge.net ...
    (comp.lang.perl.misc)
  • Whats this error in regex?
    ... I got a warning message from my perl script,it's this: ... The 703st line is in a subroutine,the subroutine is: ... sub some_sub ...
    (perl.beginners)
  • Re: suppressing selected warning messages
    ... Is there a way to suppress a specific warning message produced by Perl? ...
    (perl.beginners)