Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

Replies are listed 'Best First'.
Re: array conversion to lower case
by Athanasius (Chancellor) 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. ;)


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.

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998136]
Approved by Athanasius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-05-26 21:31 GMT
Find Nodes?
    Voting Booth?