in reply to Re: Re: "foreach" is to "next" as "map" is to ???
in thread "foreach" is to "next" as "map" is to ???

You make that look so *easy*...

Think about map, grep, and sort as operating on lists as a whole. That's what made the functional parts of Perl really click for me. for-loops operate on items that just happen to be bundled in lists. map and grep operate on lists that just happen to have items in them.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: Re: Re: "foreach" is to "next" as "map" is to ???

Replies are listed 'Best First'.
Re: Re: Re: Re: "foreach" is to "next" as "map" is to ???
by McMahon (Chaplain) on May 26, 2004 at 19:14 UTC
    Yeah, but my situation here was sort of like moving from middle-school straight to college.

    I'm pretty comfortable with looping, scalars and arrays, simple sorting, that sort of thing, but all of a sudden Sort array according to a value in each element? I needed some really heavy code.

    I have an aversion to using code that I don't understand, so I set out to understand the GRT, one chunk at a time.

    I learned a lot fast. Next to study is "the empty list technique"...
      To help understand the empty list technique, look at this code, guess what it will output, and then try it.
      my @a=((),(),()); printf "%d\n", scalar @a;
      List flattening is the key. A little more directly:
      printf "%d\n", scalar map {()} 1..3;

      The PerlMonk tr/// Advocate