Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

array conversion to lower case

by Anonymous Monk
on Oct 10, 2012 at 05:38 UTC ( #998136=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

@array = ("ONE","TWO","THREE","ABC","DEF"); i want to convert all the elements in the @array in to lowercase my o/p should like as one two three abc def can any one help me about this

Comment on array conversion to lower case
Re: array conversion to lower case
by NetWallah (Abbot) on Oct 10, 2012 at 05:42 UTC
    Use a "for" loop, and the "print" and "lc" functions.

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Re: array conversion to lower case
by Athanasius (Abbot) on Oct 10, 2012 at 05:44 UTC

    Or use map:

    15:40 >perl -e "@array = ("ONE","TWO","THREE","ABC","DEF"); @array = m +ap { lc } @array; print join(', ', @array);" one, two, three, abc, def 15:40 >

    Hope that helps,

    Athanasius <°(((><contra mundum

Re: array conversion to lower case
by davido (Archbishop) on Oct 10, 2012 at 06:37 UTC

    What is the purpose? If it's for comparison, and there's a possibility of taking Unicode input, there may be a more robust answer. Consider instead using fc (fold case) if you are using Perl 5.16.x, or Unicode::CaseFold with earlier Perl versions to obtain a case-neutral basis for comparison.

    There are some good articles on the topic, but the following are probably among the best resources available:

    I'm probably over-thinking it though. It's possible you live in an ASCII-only world, and simply need lower case for some reason other than case-neutral comparisons, in which case, this post is irrelevant. ;)


    Dave

Re: array conversion to lower case
by tobyink (Abbot) on Oct 10, 2012 at 09:36 UTC
    use Data::Dumper; @array = ("ONE","TWO","THREE","ABC","DEF"); $_=lc for @array; print Dumper \@array;
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998136]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-03 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls