Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Changing arrays w/ and w/o regex

by Corion (Patriarch)
on Nov 09, 2021 at 12:25 UTC ( #11138608=note: print w/replies, xml ) Need Help??

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2022-01-18 02:28 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (52 votes). Check out past polls.