Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Back to Remedial Perl for Me: map{} function

by Anonymous Monk
on Dec 15, 2000 at 21:52 UTC ( #46872=note: print w/replies, xml ) Need Help??

in reply to Back to Remedial Perl for Me: map{} function

Question for the monks:

Isn't it true you could do something like this (even though it's probably not in keeping with the intent of map)?

# a way to count the number of elements in a list my $count = 0; my @listOfThings = ('one', 'two', 'three'); map { ++$count } @listOfThings; print "There are $count things in your list of things.\n";

This example completely ignores the fact that the elements in the list are assigned to $_. We could care less what was in those elements. All we want to do is to execute this block once for each element that is in the list.

Replies are listed 'Best First'.
Re: Re: Back to Remedial Perl for Me: map{} function
by merlyn (Sage) on Dec 15, 2000 at 22:00 UTC

      Of course...

      I just wanted to point out that you don't have to really do anything with the elements of @listOfThings if you don't want to; you can do something completely unrelated.

      As an aside, and you may call this trolling (or you may not), I just wanted to see what people would say about this sort of use of map. It's probably a Bad Idea. It would be really interesting to see if somebody could convince me it's a Good Idea. :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://46872]
[GotToBTru]: I appreciate the ability to highlight matching brackets/ parentheses/ braces, both for my own code and the inconsistently indented code of others
[Corion]: I like editors that automatically highlight the matching parenthesis (like % in vi), but that's roughly the extent to which I like editor support ;)
[GotToBTru]: same here Corion.
[Corion]: I tried for a short time (well, 8 hours now) to get Perl::Tidy set up but then found that it doesn't support (new-style) signatures and then stopped again ;))
[GotToBTru]: changing the font color of the rest of the document just because I typed a single quote character is annoying

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-02-27 12:51 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (385 votes). Check out past polls.