Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The problem is that the list ($a .. ++$a) is not evaluating a list like you think it is. It is not doing:
But rather, it is evaluating its endpoints, and then constructing the list from that. That is the cause of your problem: You can witness a similar result from: You see, the arguments to a function aren't copies of the variables, but rather aliases -- by modifying ONE of the $x's, you've modified the others as well. Knowing this, the output of this program makes sense to me: Why is that? Well, the numerator is ++$x, and the denominator is $x--; but in subtracting 1 from $x in the denominator, we have now altered the numerator back to its original state! I've worked out a solution to your 1 .. 12 loop, then. See if you can work out why the starting point is 1. japhy -- Perl and Regex Hacker In reply to Re: Re: Re: For loop problem
by japhy
|
|