# Case conversions - PERL Beginners

On Friday, August 15, 2003, at 04:20 PM, Scott Taylor wrote: > > Any one have or know of a function to convert ugly "NAME, USER" to > "User Name"? Maybe something like: s/^(\w+), ?(\w+)\$/ucfirst(lc \$2) . ' ' . ucfirst(lc \$1)/e Hope that helps. James...

1. ## Re: Case conversions

On Friday, August 15, 2003, at 04:20 PM, Scott Taylor wrote:
>
> Any one have or know of a function to convert ugly "NAME, USER" to
> "User Name"?
Maybe something like:

s/^(\w+), ?(\w+)\$/ucfirst(lc \$2) . ' ' . ucfirst(lc \$1)/e

Hope that helps.

James

James Edward Gray II Guest

2. ## Re: Case conversions

On Fri, Aug 15, 2003 at 02:20:19PM -0700, Scott Taylor wrote:
>
> Any one have or know of a function to convert ugly "NAME, USER" to "User
> Name"?
\$ perl -le '\$_ = "NAME"; s/(.)(.*)/\$1\L\$2/; print'
Name

The function to convert a string to lower case is "lc".

HTH,

Elias

--
If you take the fact that a cat always falls on his feets and a toast
always falls on the buttered side, what happens when you tie a toast
on the back of a cat and you throw him out the window?
Elias Assmann Guest

3. ## RE: Case conversions

\$var = 'NAME, USER';
print "\$var\n";
var = reverse split(', ',\$var);
print "var\n";
\$var = join(' ',(ucfirst lc \$var[0],ucfirst lc \$var[1])); # whitout the
comma this time
print "\$var\n";

-----Original Message-----
From: Scott Taylor [mailto:scottdctchambers.com]
Sent: vendredi 15 août 2003 23:20
To: [email]beginnersperl.org[/email]
Subject: Case conversions

Any one have or know of a function to convert ugly "NAME, USER" to "User
Name"?

TIA

Scott.

--
To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
Didier Degey Guest

4. ## RE: Case conversions

> Any one have or know of a function to convert ugly "NAME, USER" to "User
Name"?

timtowtdi:

\$str = "User Name" if (\$str eq "NAME, USER");

\$str =~ s/^NAME, USER\$/User Name/;

Mark Anderson Guest

5. ## Re: Case conversions

I've just used Elias' idea to change a file's content...

Where file name is word:

perl -i -p -e 's/(.)(.*)/\$1\L\$2/' word

On Friday, Aug 15, 2003, at 23:29 Europe/Brussels, Elias Assmann wrote:
> On Fri, Aug 15, 2003 at 02:20:19PM -0700, Scott Taylor wrote:
>>
>> Any one have or know of a function to convert ugly "NAME, USER" to
>> "User
>> Name"?
>
> \$ perl -le '\$_ = "NAME"; s/(.)(.*)/\$1\L\$2/; print'
> Name
>
> The function to convert a string to lower case is "lc".
>
> HTH,
>
> Elias
>
> --
> If you take the fact that a cat always falls on his feets and a toast
> always falls on the buttered side, what happens when you tie a toast
> on the back of a cat and you throw him out the window?
>
> --
> To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
> For additional commands, e-mail: [email]beginners-helpperl.org[/email]
>
Jerry Rocteur Guest

6. ## Re: Case conversions

At 02:28 PM 08/15/2003, James Edward Gray II wrote:
>On Friday, August 15, 2003, at 04:20 PM, Scott Taylor wrote:
>
>>
>>Any one have or know of a function to convert ugly "NAME, USER" to "User
>>Name"?
>
>Maybe something like:
>
>s/^(\w+), ?(\w+)\$/ucfirst(lc \$2) . ' ' . ucfirst(lc \$1)/e
Nice, very useful! Only now I have a small problem with names like
"O'CONNELL, BOB"

Scott Taylor Guest

7. ## Re: Case conversions

On Friday, August 15, 2003, at 04:55 PM, Scott Taylor wrote:
> At 02:28 PM 08/15/2003, James Edward Gray II wrote:
>> On Friday, August 15, 2003, at 04:20 PM, Scott Taylor wrote:
>>
>>>
>>> Any one have or know of a function to convert ugly "NAME, USER" to
>>> "User Name"?
>>
>> Maybe something like:
>>
>> s/^(\w+), ?(\w+)\$/ucfirst(lc \$2) . ' ' . ucfirst(lc \$1)/e
>
> Nice, very useful! Only now I have a small problem with names like
> "O'CONNELL, BOB"
Yes you do! :) The ' character isn't covered under my \w above. I'll
switch it to a character class to show how to fix it, but you may need
to refine it a little further.

s/^([A-Z'] +), ?([A-Z']+)\$/ucfirst(lc \$2) . ' ' . ucfirst(lc \$1)/e

Hope that helps.

James

James Edward Gray II Guest

8. ## RE: Case conversions

At 02:46 PM 08/15/2003, Degey, Didier wrote:
>-----Original Message-----
>From: Scott Taylor [mailto:scottdctchambers.com]
>Sent: vendredi 15 août 2003 23:20
>To: [email]beginnersperl.org[/email]
>Subject: Case conversions
>
>Any one have or know of a function to convert ugly "NAME, USER" to "User
>Name"?
Strange email thingy you have, putting the reply inline with the original
and forcing it to the top.
>\$var = 'NAME, USER';
>print "\$var\n";
>var = reverse split(', ',\$var);
>print "var\n";
>\$var = join(' ',(ucfirst lc \$var[0],ucfirst lc \$var[1])); # whitout the
>comma this time
>print "\$var\n";
This works well, too, and join seems to fix the problem with names having
"'"s in them.

Thanks.

Scott Taylor Guest

9. ## Re: Case conversions

On Friday, August 15, 2003, at 05:09 PM, Scott Taylor wrote:
>> \$var = 'NAME, USER';
>> print "\$var\n";
>> var = reverse split(', ',\$var);
>> print "var\n";
>> \$var = join(' ',(ucfirst lc \$var[0],ucfirst lc \$var[1])); # whitout
>> the
>> comma this time
>> print "\$var\n";
>
> This works well, too, and join seems to fix the problem with names
> having "'"s in them.
Na, it's the split() that fixed that. ;)

James

James Edward Gray II Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•