Hello, On Dec 2 14:36 Arvin Schnell wrote (shortened):
On Wed, Dec 02, 2009 at 02:22:06PM +0100, Johannes Meixner wrote:
Hello,
is such code allowed: -------------------------------------------------------------------- list < string > words = [ "Jane", "John" ]; integer index = -1; foreach( string word, words, { index = index + 1; words[index] = "Hello " + word; } ); -------------------------------------------------------------------- Is in any case the result words == [ "Hello Jane", "Hello John" ] ?
Use maplist:
words = maplist(string word, words, { return "Hello " + word; });
Regardless of maplist/mapmap: Is my above code using foreach allowed? My actual case is a bit more complicated like: ----------------------------------------------------------------------- list < string > words = [ "Jane", "World", "John" ]; integer index = -1; foreach( string word, words, { index = index + 1; if( "World" == word ) { words[index] = "Hello " + word; } } ); ----------------------------------------------------------------------- Is in any case the result words == [ "Jane", "Hello World", "John" ] ? Assume the list is huge. Wouldn't then ----------------------------------------------------------------------- words = maplist( string word, words, { if( "World" == word ) { return "Hello " + word; } else { return word; } } ); ----------------------------------------------------------------------- consume unnecessarily much memory and CPU (two lists and all elements are copied instead of "in place" modification only where needed via foreach)? Kind Regards Johannes Meixner -- SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany AG Nuernberg, HRB 16746, GF: Markus Rex -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org