简体   繁体   中英

what is the difference between the \L and the lc function in Perl?

What is the difference between \\L and lc in Perl?

Where are these two applicable?

"foo\Lbar\Ebaz"

is just another way of writing

"foo".lc("bar")."baz"

It happens after interpolation, so

"foo\L$bar\Ebaz"

is just another way of writing

"foo".lc($bar)."baz"

\\L..\\E is useful in the substitution operator's replacement expression which is a string literal.

s/(...)(...)(...)/\L$1\E!$2!\L$3\E/

To use lc , you'd have to use /e

s/(...)(...)(...)/ lc($1)."!$2!".lc($3) /e

lc is a function that takes an expression and returns the lowercase version of that expression. \\L is used as a way to make letters in a substring lower case (is terminated by \\E )

For example:

print lc("STeve");
#prints steve  

print "DOW\LNLO\EAD\n";
#prints DOWnloAD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM