Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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 (Canon) 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 a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-07-21 06:18 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (444 votes). Check out past polls.