Professional Web Applications Themes

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. #1

    Default 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. #2

    Default 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. #3

    Default 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]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    Didier Degey Guest

  4. #4

    Default 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. #5

    Default 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. #6

    Default 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. #7

    Default 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. #8

    Default 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. #9

    Default 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

Similar Threads

  1. Question PDF to PDF/A conversions
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: January 31st, 08:11 PM
  2. batch conversions
    By zimmy6911 in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 9
    Last Post: April 26th, 06:07 PM
  3. #23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
    By nvivo at mandic dot com dot br in forum PHP Development
    Replies: 0
    Last Post: October 19th, 12:17 PM
  4. ASP/SQLServer character conversions
    By Félix López in forum ASP Database
    Replies: 1
    Last Post: July 21st, 08:20 PM
  5. Date conversions...
    By Mark in forum Microsoft Access
    Replies: 3
    Last Post: July 7th, 05:43 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139