----- Original Message ----- From: "Adamiec, Larry" <[EMAIL PROTECTED]> Date: Thursday, November 11, 2004 3:26 pm Subject: reg expression in an if test
> I am testing a small piece of code before inserting it into a large > program. I have one field where the user will insert a 9 character > string. The first character must be an upper case 'L' while the > remainder must be digits. > > Does Perl have any type of toupper function? I know I can use the > modifier 'i' in my search string to ignore case but I must insert an > upper case 'L' into the database. read up on build'ins 'uc' and 'lc' > > Is there a different way to check the last 8 characters and the length > of the string than what I am doing? I am sure there are many other ways here is one print "$str => OK" if $str =~ /^L\d{8}$/; > > Larry Adamiec > > Here is the code > #################################### > #!/usr/local/bin/perl > use strict; > use warnings; > > my $str; > > $str = "L12345678"; > > if ( ($str =~ /^L\d{8}/) && (length($str) == 9) ) > { > print "OK"; > } > else > { > print "Bad"; > } > print "\n"; #!PERL use warnings; use strict; my $str = "L12349998"; $str = uc $str; if ( ($str =~ /^L\d{8}$/) ) { print "OK"; } else { print "Bad"; } print "\n"; > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>