Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Changing arrays w/ and w/o regex

by Corion (Patriarch)
on Nov 09, 2021 at 12:25 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found