Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Replacing whitespaces with a regex

by choroba (Bishop)
on Mar 04, 2013 at 16:44 UTC ( #1021674=note: print w/replies, xml ) Need Help??

in reply to Re: Replacing whitespaces with a regex
in thread Replacing whitespaces with a regex

map in a void context can be replaced by for:
s/\s+$/ / for @array;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: Replacing whitespaces with a regex
by ISAI student (Scribe) on Mar 04, 2013 at 17:16 UTC
    Yes. But map brings me memories of the times I got to know the PERL magic, +and more than 1 way to do it. If I use for or foreach, I feel like I +use TCL/Python, and not enjoying an experience unique to PERL. map seems, to me, as more decidedly PERLISH that for. It's a personal thing, and this is why I have said that it is a person +al prefernce (unless there is a performance consideration).

      I'm a huge fan of map, but I wouldn't use it that way. Most recommendations on Perl best practices that I've seen suggest against map in void context (using for/foreach instead), and I think that one makes a lot of sense.

      When I see map, I expect that it is being used in the conventional higher-order function way: taking a list, applying a given function to each item in the list, and returning the resulting list. The original array isn't changed.

      This gives me a strong visual cue when I'm reading code: if I see map, it's creating a (modified) copy of a list, if I see for/foreach loop, then I'm making a change to the list itself. I would go so far as to say that these are the fairly standard (in so far as Perl has standards) and idiomatic way of using map and for/foreach.

      Just as a historical side-note, map isn't a Perl creation; it comes from the world of functional programming. This is also where the recommended usage (as suggested above) comes from, as that is how it is used in most languages. Many languages have a map function (including Python).

      You are, of course, free to use it any way you want, but don't be surprised if most programmers (especially those familiar with functional programming) expect it to be used as described above.

      Christopher Cashell

        I have learned something new. Thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021674]
[erix]: ( and when teleology was brought up, during my biology-study., I couldn't get an answer either )
[1nickt]: FTR I agree with you about "design." Just not sure about the trajectory of evolution. THere are a lot of dead-ends in the evolutionary paths. I suspect homo sapiens is just one of them.
[james28909]: thanks for the vid holli, i do like it. thanks for sharing :)
[holli]: gives me goosebumps every time I watch it
holli gotta grab some groceries before dawn. l8ters
[erix]: s/dawn/dusk/
[erix]: (you're welcome :P)
[james28909]: you know, i had a thought a few mnths back. what if this universe were just a puzzle, waiting for life to figure it out!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-12-15 14:39 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.