in reply to Re: sprintf and for loop weirds???
in thread sprintf and for loop weirds???

scalar(@a) returns the number of elements in @a, not the index of the last element. Using $n <= scalar(@a) will iterate an extra time, past the end of the array. The original poster's use of $n < scalar(@a) was correct.

In fact, after fixing the missing parentheses in both snippets, both snippets produce the expected results. However, the missing parentheses make it clear we're not looking at the original poster's actual code.