Velocity Reviews > Perl > Newbie: test array for lower case

# Newbie: test array for lower case

Mark
Guest
Posts: n/a

 02-13-2005
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];
}

Jürgen Exner
Guest
Posts: n/a

 02-14-2005
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

Joe Smith
Guest
Posts: n/a

 02-14-2005
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

Mark
Guest
Posts: n/a

 02-14-2005
Thanks for both suggestions!

Mark.

"Mark" <(E-Mail Removed)> wrote in message
news:67LPd.1824\$(E-Mail Removed)...
> 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];
> }
>
>