From: Willem on
Mr P wrote:
)> s/^(CAT)/$c++ ; "$1 $c:/e foreach @a;
)>
)> and don't use map without returning a list. foreach modifier is better
)> for that.
) respectfully- this is just another way to specify a for loop-
) precisely what I was trying to avoid..

map is also just another way to specify a for loop.

) Thanks Uri and everyone, but to summarize , what I'm attempting to do,
) apparently, isn't supported..

Of course it is. If you want to keep the original array intact,
and you want a *new* array with the counters added, *then* map is
useful:

my $c = 0;
my @result = map { $_.(/^CAT$/ && ' '.++$c) } @source;

But that's still a loop over each separate element of the array.

) It seems odd to me that it's not, I want to MAP an incremented value
) over an array- sounds like a perfectly logical thing to want to do?
)
) I realize of course from my, and everyone else's contributions, there
) are myriad ways to accomplish this with for or foreach. But that's
) precisely what I DID NOT want to do. THat's the beauty and elegance of
) map- it operates in 2D.

No it doesn't. It's just a for loop that returns an array of results.

This is map, basically:

sub map (&@) {
my $func = shift;
my @result;
push @result, &$func for @_;
return @result;
}

If you don't use the result of map, then it is *exactly* the same as for.
(In recent versions of perl, map even checks if it is called in a void
context, and if so it switches to a for-loop.)


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
From: Uri Guttman on
>>>>> "TM" == Tad McClellan <tadmc(a)seesig.invalid> writes:

TM> Uri Guttman <uri(a)StemSystems.com> wrote:
>> but i don't think
>> i will help you until

TM> You are slow on the uptake :-)

and you just learned this now? :)

TM> I've been ignoring this poster for years.

TM> http://groups.google.com/groups/search?as_umsgid=1135692143.665441.112530%40g14g2000cwa.googlegroups.com

yep, same old dog and no new tricks.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------