in reply to Cleverness - \L\u in strings

Im not sure about the \L and \u charachters, clearly they have some defined order of operations, which appears to be from left to right. I.e. for your first example, first the \L triggers, making everything lower case, then the \u triggers, making the first uppcase. This can be easily seen with the functions below, as you can clearly see the order of operations.

Replies are listed 'Best First'.
Re: Re: Cleverness - \L\u in strings
by thelenm (Vicar) on May 31, 2002 at 19:04 UTC
    The order in which \L and \u are applied isn't necessarily left to right... you get the same result from "\u\LhElLo" as you do from "\L\uhElLo". Rather, perl is behaving as it thinks the programmer intended by putting \u and \L right next to each other, in either order.

    (Somewhat off-topic)... I could swear that I've read an anecdote before that went something like this: Someone expected "\L\uhElLo" to produce "hello", not "Hello", because he knew that they were implemented internally with ucfirst and lc. He expected the behavior to be the same as lc(ucfirst("hElLo")). But he was pleasantly surprised to find that it actually produced "Hello". When he mentioned this to Larry, Larry just smiled (and maybe said something pithy). Has anyone else heard this anecdote? I've spent probably an hour looking through my Perl books and doing Google searches, trying to find it, and it's driving me nuts.

    -- Mike

    --
    just,my${.02}