Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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


 
Reply With Quote
 
 
 
 
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


 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
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];
> }
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression to Replace UPPER Case Text with lower case text penny Perl Misc 28 03-10-2008 01:14 AM
ASP.net / Indexing Service ...results in lower case =?Utf-8?B?ZG90bmV0dGVzdGVy?= ASP .Net 0 09-29-2005 07:10 PM
lower case to upper case Janice C Programming 17 12-14-2004 02:35 PM
Regular expression weirdness with upper and lower case semovrs@concord.edu Perl 4 12-07-2004 01:35 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments