Re: why Perl complaints my script




Chen Li wrote:
for ($k; $k>=1;$k--) {$result*=$n--;}#line 15

Useless use of private variable in void context at
fac1.pl line 15.

Well that's fairly clear isn't it?

And if it's not, what part of the explaination of that message in the
reference manual did you find unclear? Remember as a beginner you are
in a unique postion to tell us where the manuals are unclear. We can't
tell because we know what it's trying to say already. So, please,
whenever you find something hard to understand, cite the _exact_
passage of the manual that you are having trouble with so that we get a
chance to improve it.

<fish>

Note that "private" here is a rather odd choice of word, the word we
usually use in perl is "lexical".

What the warning is telling you is that your code is exactly the same
as

for ( ; $k>=1;$k--) {$result*=$n--;}#line 15

The first expression in for(;;) is there only for the sake of its side
effects. The expression is evaluated in such a way that is doesn't have
a return value. This is called evaluating the expression in a void
context. The expression $k has no side effects so evaluating it a void
context is, to quote the warning, "useless".

</fish>

.



Relevant Pages

  • Re: "Your Fiddle and Banjo Crap"
    ... Sword" and in the parlance that meant it was very good at slicing and ... where the context is hardly optimistic: ... the undiscovered country from whose bourne no traveler returns." ... Evaluating all GUIs by the example of Windows is like evaluating all cars ...
    (rec.music.filk)
  • Re: ConTeXt and LaTeX by authoritative figure
    ... I am not an authoritative figure in either Latex or Context, but I have experience with both Latex and Context. ... There are two areas where latex and context differ: if you want to change the look and feel of your documents, and if you want to write macros or environments that do something non-trivial. ... There are, however, quite extensive manuals: a beginner's manual, a user manual, a metafun manual, a widgets manual, a flowchart manual, a mathml manual, a columns manual, a figure database manual, a grid manual, amongst others. ...
    (comp.text.tex)
  • Re: how to release memory?
    ... Cases and are undefined behaviour. ... no such statement for "(void) p". ... C99 6.5.4, Cast operators, also says nothing about not evaluating the ... I believe the compiler has the option to ...
    (comp.lang.c)
  • Re: Amazing double-talk from creationists
    ... boris wrote: ... (Top post moved to context) ... evidence. ... they have had years of training and experience in evaluating ...
    (talk.origins)
  • Re: how to release memory?
    ... Cases and are undefined behaviour. ... no such statement for "(void) p". ... C99 6.5.4, Cast operators, also says nothing about not evaluating the ...
    (comp.lang.c)