http://qs321.pair.com?node_id=11138608


in reply to Changing arrays w/ and w/o regex

lc is a function and in your first case, you are throwing away the result of the function. This is also why Perl warns you about throwing away the result of a function . "void context" means that you don't care about the result of a function, which is uncommon when calling a function.

In the second case, you are using the result of the function, by using it in the replacement part of s///.

When rewriting an array, it's common to use the map function to turn each element of the (old) array into a new value:

@x = map { lc( $_ )} @x;

I believe this can be written even shorter as

@x = map lc, @x

... but that is overly short especially if you are not yet familiar with map.

Updated: Added map as example