in reply to "foreach" is to "next" as "map" is to ???

Reading between the lines (or rather between the nodes) and assuming that you are trying to combine the two loops in this node, then the empty list technique is the most applicable.

my @sorted = map{ substr $_, 5; }sort { $b cmp $a } map{ m[,\s+(\d+)] ? sprintf '%05d%s', $1, $_ : () } @msgs;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: "foreach" is to "next" as "map" is to ???
by McMahon (Chaplain) on May 26, 2004 at 19:00 UTC
    Wow. You make that look so *easy*... =)

    Thanks for jumping in. I've been breaking apart the GRT into little sections, asking questions about various parts. I guess you figured that out.

    There's still lots of stuff here for me to study, but this is definitely what I was trying to get to.

      It's Perl, it's original design and many years of refinement that make this sort of thing easy. A language developed to solve problems rather than comply to some academic or commiteed theory.

      It just takes a while to encounter all the ways to use it, and a bit longer to be able to remember them all. I'm still a relative novice and still learn something new here almost every day.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      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

        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"...