Newbie: test array for lower case - Perl

This is a discussion on Newbie: test array for lower case - Perl ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Newbie: test array for lower case

  1. Default Newbie: test array for lower case

    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];
    }



  2. Default Re: Newbie: test array for lower case

    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



  3. Default Re: Newbie: test array for lower case

    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

  4. Default Re: Newbie: test array for lower case

    Thanks for both suggestions!

    Mark.


    "Mark" <m.misener@sympatico.ca> wrote in message
    news:67LPd.1824$QR.68881@news20.bellglobal.com...
    > 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];
    > }
    >
    >




+ Reply to Thread

Similar Threads

  1. Regular Expression newbie question about upper & lower case
    By Application Development in forum RUBY
    Replies: 5
    Last Post: 09-30-2007, 12:10 PM
  2. convert f77 code from mixed case to lower case
    By Application Development in forum Fortran
    Replies: 44
    Last Post: 07-27-2007, 01:09 AM
  3. Can Pine lower-case a whole message?
    By Application Development in forum Pine
    Replies: 9
    Last Post: 07-07-2007, 04:48 AM
  4. lower-case()-Function in XQuery
    By Application Development in forum XML SOAP
    Replies: 2
    Last Post: 08-03-2006, 07:02 AM