in reply to foreach with array elements problem

I don't think it works like that. You're apparently trying to assign all the values to $array[0], which I'm figuring isn't what you had in mind. If you're simply trying to put the index of the array into the corresponding array element, then perhaps you should consider:

foreach $i (1 .. 10) { $array[$i] = $i; }

... or words to that effect.

Replies are listed 'Best First'.
Re^2: foreach with array elements problem
by Errto (Vicar) on Oct 22, 2005 at 02:59 UTC
    Of course, if that's what you're going for you could achieve that much more easily by saying
    @array = (1 .. 10);

      ++, Errto... it's the C programming that makes me do everything the hard way... Some day I'll learn...

Re^2: foreach with array elements problem
by Anonymous Monk on Oct 22, 2005 at 03:25 UTC
    "You're apparently trying to "

    If you don't have much sense to understand things, it definitely went too far for you to guess things. Don't even think about it, don't do things that are beyong your capability. It is 100% obvious that he never wanted what you thought he wanted. His question was simply and straight: in the foreach syntax, why the var cannot be an array element?

      I'm sure that if the OP feels I have overstepped my bounds, s/he can speak up and say something. In this case, the words used by the OP, and the code s/he showed, created an ambiguity that could not readily be resolved. I chose one possibility, and responded to it. While my response was awkward insofar as Perl is concerned, and it made an assumption that might be false, it was the first one that actually tried to answer the OP's question. I at least made an effort to help someone, instead of criticizing him or her for real or imagined faults.

      Now, tovarishch, I have had enough rudeness from you. If you choose to discuss matters with me in a civilized manner, I will be glad to do so. If you choose to continue to be rude, I won't reply, OK? Have a nice day.

      " Don't even think about it, don't do things that are beyong your capability."

      Overlooked this point... if I don't try to do things that are beyond (note the spelling) my capability, they will always remain beyond me. Biting off more than you can chew is a good way of developing your skills.