xenchu has asked for the wisdom of the Perl Monks concerning the following question:

Suppose you have a regexp:

@results = map {/.+\/.+\/(.*).pm$/} @list;
My question is this: If the items in @list are both upper and lower case how do you make the first letter of selected items Uppercase(or lowercase) for all items? I tried several methods but none worked.

Thanks,

xenchu

Update:HyperZonk is correct. The answer I was looking for was the one BrowserUK provided. He was also correct about the errors in my regexp. I did not explain what I was trying to do. @list would contain all the files on my system that ended in .pm. I thought at the time that some of the modules had a lowercase as well as an uppercase version(I was wrong about that too). I was attempting to ensure that the resulting list had no duplicates. That is why the perfectly logical uc(@results) would not have been useful.

Anyway I thank you all. Everytime I ask a question on this site I become a better programmer.

xenchu

Update2:HyperZonk, the reason I don't require anything between the second slash and .pm is that I can't think of anything that fits. It is (or should be) a module name. I think I'll go buy a copy of Simple Regular Expressions for Morons. If it doesn't look too advanced.



****sigfilesigfilesigfilesigfilesigfilesigfilesigfilesigfile

Perl has one Great Advantage and one Great Disadvantage:

It is very easy to write a complex and powerful program in three lines of code.

********************************************

The Needs of the World and my Talents run parallel to infinity.

Replies are listed 'Best First'.
Re: Uppercasing Regex Output
by BrowserUk (Patriarch) on Dec 07, 2003 at 20:37 UTC
    @results = map {/.+\/.+\/(.*).pm$/ and ucfirst($1) } @list;

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!
    Wanted!

Re: Uppercasing Regex Output
by HyperZonk (Friar) on Dec 07, 2003 at 20:44 UTC
    xenchu:
    BrowserUK's answer is the one you are looking for, but I don't think that your original regex is doing what you want it to do (I may be wrong).

    Just as a start, you are matching any character before the pm at the end; you might want to escape that dot (that is, your original regex will match "apm" as well as "foo.pm"). Secondly, you are not requiring anything before the something-p-m at the end of the string. So, as noted, apm will match (with nothing captured in the map) as will .pm (with nothing captured there, either).

    Also, note that a string ending in "sopm" will end up capturing an "s" in the map.

    Update: Just noticed when re-reading my comments: I should have said that you are not requiring anything between the second / and the something-p-m at the end of the string.


    -HZ
Re: Uppercasing Regex Output
by shenme (Priest) on Dec 07, 2003 at 20:41 UTC
    @results = map { ucfirst } @results;
    and the "legs on the snake" version
    @results = map { ucfirst lc } @results;
    The perlre page notes that there are perlfunc parallels for each of the quoting and RE escapes \u   \l   \U   \L .
Re: Uppercasing Regex Output
by pg (Canon) on Dec 07, 2003 at 20:40 UTC

    After you got your result list:

    @result = ("abc", "ABC", "egd", "HELLO"); @result = map {ucfirst} @result;; print join(",", @result);
Re: Uppercasing Regex Output
by duff (Parson) on Dec 07, 2003 at 20:37 UTC
    ... how do you make the first letter of selected items Uppercase(or lowercase) for all items?

    I'm not exactly sure what you mean by this. It sounds at first blush like you just want to use either ucfirst or lcfirst.