[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Elementary question (I think)



On Thu, 11 Mar 1999 15:34:52 +0000, Chris Sansom wrote:

>Suppose I have an array @stuff, when can and can't I use this syntax:
>
>for ($i = 0; $i <= @stuff, $i++) {
>...
>}
>
>I was under the impression that this was perfectly safe, but it seems to
>break my script. As soon as I change all those @'s in this type of
>construct to $# it works just fine.

You're doing one loop too many. Result is that $stuff[$i] is undefined
in that last loop.

Either use:

	for ($i = 0; $i < @stuff; $i++) { ... }
or
	for ($i = 0; $i < $#stuff; $i++) { ... }

The last item in @stuff is number $#stuff, @stuff is one more if $]==0
(default/recommended).

	Bart.

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org