Newbie: test array for lower case

Discussion in 'Perl' started by Mark, Feb 13, 2005.

  1. Mark

    Mark Guest

    Hi,

    I'm having problems with my testing for lower case in an array element.
    In the example below, my 'if' statement doesn't seem to test true for lower
    case.
    It falls through to the block assuming it's upper case.

    Anyone know what's wrong?

    Thanks.

    # Try to determine case and change for consistency
    if ($array[0] eq ["a-z"]) {
    print "\narray[0] is lower case: $array[0]\n";
    $array[0] = lc $array[0];
    $array[1] = lc $array[1];
    }else{
    print "\narray[0] is upper case: $array[0]\n";
    $array[0] = uc $array[0];
    $array[1] = uc $array[1];
    }
     
    Mark, Feb 13, 2005
    #1
    1. Advertising

  2. Mark wrote:
    > Hi,
    >
    > I'm having problems with my testing for lower case in an array
    > element. In the example below, my 'if' statement doesn't seem to test
    > true for lower case.
    > It falls through to the block assuming it's upper case.
    >
    > Anyone know what's wrong?
    >
    > Thanks.
    >
    > # Try to determine case and change for consistency
    > if ($array[0] eq ["a-z"]) {


    What is
    ["a-z"]
    supposed to mean? I may be wrong by to me it looks like you are comparing
    the texual value of the first element of @array with an anonymous array,
    that has the only element "a-z".

    Are you simply trying to check if the string in $array[0] is all lower case?
    Then just do
    if ($array[0] eq lc $array[0]) {
    print "$array[0] is all lower case\n";
    }

    jue
     
    Jürgen Exner, Feb 14, 2005
    #2
    1. Advertising

  3. Mark

    Joe Smith Guest

    Mark wrote:

    > # Try to determine case and change for consistency
    > if ($array[0] eq ["a-z"]) {


    No, 'eq' does not work that way.

    if ($array[0] eq 'a simple string') { print 'Match' }
    if ($array[0] =~ /[a-z]/) {print 'Has at least one lowercase letter' }
    if ($array[0] =~ /^[a-z]+$/) {print 'Consists of only lowercase' }

    -Joe
     
    Joe Smith, Feb 14, 2005
    #3
  4. Mark

    Mark Guest

    Thanks for both suggestions!

    Mark.


    "Mark" <> wrote in message
    news:67LPd.1824$...
    > Hi,
    >
    > I'm having problems with my testing for lower case in an array element.
    > In the example below, my 'if' statement doesn't seem to test true for
    > lower case.
    > It falls through to the block assuming it's upper case.
    >
    > Anyone know what's wrong?
    >
    > Thanks.
    >
    > # Try to determine case and change for consistency
    > if ($array[0] eq ["a-z"]) {
    > print "\narray[0] is lower case: $array[0]\n";
    > $array[0] = lc $array[0];
    > $array[1] = lc $array[1];
    > }else{
    > print "\narray[0] is upper case: $array[0]\n";
    > $array[0] = uc $array[0];
    > $array[1] = uc $array[1];
    > }
    >
    >
     
    Mark, Feb 14, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    714
    Jürgen Exner
    Dec 7, 2004
  2. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    ASP.net / Indexing Service ...results in lower case

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Sep 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    =?Utf-8?B?ZG90bmV0dGVzdGVy?=
    Sep 29, 2005
  3. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,194
    Richard Bos
    Dec 14, 2004
  4. Peter Vanderhaden
    Replies:
    5
    Views:
    138
    SpringFlowers AutumnMoon
    Sep 30, 2007
  5. penny
    Replies:
    28
    Views:
    2,620
    Charlton Wilbur
    Mar 10, 2008
Loading...

Share This Page