http://qs1969.pair.com?node_id=63200

coolmichael has asked for the wisdom of the Perl Monks concerning the following question:

I've been trying to wrap my head around map. I think I was going about it all wrong, trying examples and such just to see how it worked. It was probably to complicated for me, so I gave up and tried to play with grep for a while. It was a lot easier to understand. So now back with map, I've got a function that calculates a running total. My first thought was

map {$n[$#n+1]=($count+=$_)} <DATA>;

but then I realized that map was returning a list anyway, so I probably didn't need @n at all. I came up with

@n=map {$count+=$_} <DATA>;

Is this a good way to do it?

Also, I was wondering if you could do it with grep? I don't know why you'd want to, but it seems to me like you should be able to.

@n=map {$count+=$_} <DATA>; print "@n\n"; __DATA__ 1 2 3 6 -5 6
outputs this
1 3 6 12 7 13
which is what I was aiming for.