in reply to for vs foreach

Well, I'm getting roasted...so bye bye answer!!! Whats the reason for the - votes? What did I have/do wrong? The beatings will continue until morale raises.

Replies are listed 'Best First'.
RE:(2) for vs foreach (-- for incorrect answer)
by Russ (Deacon) on Jul 17, 2000 at 00:57 UTC
    Macphisto, I didn't see your original post, but it sounds as if you simply posted something incorrect. That doesn't excuse any -- votes (and I'm giving you ++, because a wrong answer does not deserve a vote-down in SoPW).

    However, let me encourage you not to simply remove your original post. There is a much better chance for others to learn something if you will just modify your post by adding an update tag, like:
    Update: LSD flashbacks caused me to confuse valid Perl code with Mork and Mindy's home phone number. Here is what I should have said...

    That way, you can avoid negative votes (which, again, should not happen simply for incorrect posts) for your original post, and even more negative votes for a "deleted" post.

    Thanks for posting, and welcome to our community.

    Russ
    Brainbench 'Most Valuable Professional' for Perl

      Thanks, Russ. I appreciate the open mind. I got blasted for that post. I didn't check my code and paid for it! Ouch! The beatings will continue until morale raises.
RE: Re: for vs foreach
by perlmonkey (Hermit) on Jul 14, 2000 at 20:39 UTC
    See the comments above, your statement is incorrect. for can just as easily iterate over a list as foreach (without an explicit iterator), they are completly interchangeable.
    @a = ( 1, 2, 3, 4); for(@a) { print; } print "\n"; foreach(@a) { print; } print "\n"; for($i=0; $i<@a; $i++) { print @a[$i]; } print "\n"; foreach($i=0; $i<@a; $i++) { print @a[$i]; } print "\n";
    Results:
    1234 1234 1234 1234