in reply to Comparing lower to upper case

Answering your first question:

1. Figure out if the second character is a letter of the alphabet?

You could simply do a pattern match, like so:
if ($str =~ m/\d[a-zA-Z]\d+/) { print "Ok!\n"; } else { print "Invalid format! Must be: [digit][letter][digit][digit] ... \n +"; }


UPDATE: pardon for this minor slip, but you are certainly right. It should have been [a-zA-Z] instead of just \w. ;/.

_____________________
open(I,$0);<I>;$~=$/;$/='~';$_=<I>;($/)=/(.)$~/;s/[$~~]//g;/(v)/;$-=$-[0];s;\Q$/\E;$~;g;($/,$^)=/^(.)(.)/;
#%  xxxxxx   xx-+  xx    xxx xx  xx       xx  xx   xxx   xxxxx+ xx  xx xxxx xxxxx  ......+
#x xxxxvxxx xx  xx xv   xxxx x+ %+  ===== xx  xx  xx xx  x+  =x xx xx  xx   xx xx ...+
#x xx xx xx xx  xx xx  xx xx xxx+         xxxxxx xx   +x xx     xx+x-  xxxx xxxx ........+
#% xx xx xx xx  xx xx xx  x+ xx xx  =+=== xx  xx xxxx-xx xx  =x +x xx  xx   xx xx ...+
#% xx xx xx  -+x+  xxx+   xx xx  xx       xx  xx x+   xx xxx+xx xx  xx xxxx xx  xx ....+~
for(split/$~/){s,[ $/],,g;/(.)$/;$l=$-[0];/(.)/||next;$_=chr$-+$l;$".=($1=~/$^/)?" \u$_":$_;}print$";

Replies are listed 'Best First'.
Re: Re: Comparing lower to upper case
by jsprat (Curate) on Jun 11, 2002 at 18:44 UTC
    But... \w will match any "word character", which is defined as "alphanumeric plus '_'", so that regex will match '2_4' and '234' as well as '2A4'.

    You'd need either /\d[a-zA-Z]\d+/ or /\d[:alpha:]\d+/.

Re: Re: Comparing lower to upper case
by joshua (Pilgrim) on Jun 11, 2002 at 19:01 UTC
    Won't \w match any letter, number, or underscore?
    if ($str =~ m/\d[A-Z]\d+/) { print "Ok!\n"; } else { print "Invalid format! Must be: [digit][letter][digit][digit] ... \n +"; }

    Joshua

    A reply falls below the community's threshold of quality. You may see it by logging in.