in reply to Data to hash via map problem

The following should work like your current line:
my %clipNames = map {(split /,/, $_)[0,1]} @clips;
But if you have a lot of clips I should warn you that the foreach loop will be a lot faster than map with current Perls. (This is a bug that should be fixed in the next release.)

Replies are listed 'Best First'.
RE: Re (tilly) 1: Data to hash via map problem
by merlyn (Sage) on Sep 06, 2000 at 18:26 UTC
    Don't raise so much FUD about map, tilly! It's only slower in the current releases when the output array is larger than the input array.

    One-to-one or one-to-less-than-one mapping is still quite fast: as fast as using a grep (on which the map code was originally based).

    What was improved was the less common but equally useful case of one-to-more-than-one (more outputs than inputs), and that speedup code is in 5.7.0 and soon will be in 5.6.1 (about a month, I'm hearing from P5P).

    -- Randal L. Schwartz, Perl hacker

      And the map under discussion is a one-to-two map, so the big slow-down does apply here.

      There are also plenty of cases where map leads to slower code, not because of map being slow but because of memory requirements or the need to create lots of small data structures.

      map often leads to less error-prone code and that is a strong reason to use it.

              - tye (but my friends call me "Tye")
      You are kidding around, right?

      As tye mentioned, this is exactly the case that hit the slowdown, and who should know better than me...? :-)

      Sheesh, I guess I will have to do something else sometime so you can have more to kid me about!