in reply to Re: foreach/map equivalency
in thread foreach/map equivalency

This is wrong. map produces a list without having to perform any stack or array operations. That's why it's not spelled for or foreach. That's also why rob_au is getting null values.

Update: That is to say, map handles the list construction for you, and assigning the results to some sort of variable handles the list assignment. Under the covers, it's free to use whichever linked list or stack operations it prefers.

Replies are listed 'Best First'.
Re: Re: Re: foreach/map equivalency
by gloryhack (Deacon) on Nov 11, 2001 at 04:07 UTC
    Updated in response to upstream update...

    So, then, if it does, or can, iterate over the source list in order to create the destination list, how is it that I am wrong?

    I'm not trying to be right, I'm trying to gain an understanding of why I'm not.

      No push necessary:

      my @times_two = map { $_ * 2 } (1 .. 12);
      That doesn't mean you can't use a push, just that you don't have to to make one list:

      my @duplicate; my @times_two = map { my $val = $_ * 2; push @duplicate, $_; $_ } (1 . +. 12);

      Does that make it clearer?

        I'm lost. Upstream a ways, you said "This is wrong." What, precisely, is wrong? I thought, apparently mistakenly, that you were taking exception to my statement that map() iterates over the list... now, it seems that it was my assertion that the two cases were not equivalent because the second didn't use push() as the first did...

        I'm in a maze of twisty little passages...