Ask a Question related to PERL Beginners, Design and Development.

  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. Similar Questions and Discussions

    1. Hebrew Calendar conversions?
      Is there a Perl module for Hebrew->Gegorian and Gregorian->Hebrew date conversions? -- Shmuel (Seymour J.) Metz, SysProg and JOAT ...
    2. batch conversions
      how can i use the automate function to convert a number of images from jpg to gif, and resize at 50% of the original? so that they are...
    3. #23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
      ID: 23026 Comment by: nvivo at mandic dot com dot br Reported By: mfischer@php.net Status: Open Bug Type: ...
    4. ASP/SQLServer character conversions
      Hello, I have some rows in a table in a SQLServer database which contain some characters from the greek alphabet. The problem is they are not...
    5. Date conversions...
      I'm creating a new database program, but I need to import some data from an old program (both Acc2000). Howerver, some of the dates stored in the...
  3. #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

  4. #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:scott@dctchambers.com]
    Sent: vendredi 15 août 2003 23:20
    To: [email]beginners@perl.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-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    Didier Degey Guest

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

  6. #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-unsubscribe@perl.org[/email]
    > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    >
    Jerry Rocteur Guest

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

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

  9. #8

    Default RE: Case conversions

    At 02:46 PM 08/15/2003, Degey, Didier wrote:
    >-----Original Message-----
    >From: Scott Taylor [mailto:scott@dctchambers.com]
    >Sent: vendredi 15 août 2003 23:20
    >To: [email]beginners@perl.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

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

Posting Permissions

  • You may not post new threads
  • You may 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