Newbie: test array for lower case

M

Mark

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

Jürgen Exner

Mark said:
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

Joe Smith

Mark said:
# 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top