Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Map Vs Foreach

by ikegami (Patriarch)
on Nov 26, 2009 at 22:59 UTC ( [id://809665]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Map Vs Foreach
in thread Map Vs Foreach

The both "visit" each element of a list

I was talking about their purpose.

The only way I can think of map on its own "transforming" a list is constructs like:

The whole purpose of map is to transform a list.

my @b = map uc, @a; # 1 to 1 my @b = map { $_ => uc($_) } @a; # 1 to N, const ratio my @b = map { /^#/ ? () : $_ } @a; # 1 to N

But then it's the combination of map and the assign statement

No way. You don't have to assign the list to anything. You could pass it to join, for example.

print join '|', map uc, qw( a b c );

Replies are listed 'Best First'.
Re^4: Map Vs Foreach
by JavaFan (Canon) on Nov 27, 2009 at 09:36 UTC
    In my dictionary, that's as much "transforming" as addition "transforms" scalars. For me, something that doesn't change, isn't transforming - it's static.
      Are you confusing list and array? I didn't ask sooner since I know you understood the different before. But what you say doesn't make sense otherwise.
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://809665]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found