regex - PERL: What's missing in my regexes? -
this part of school project. cannot figure out what's problem in regexes. have more work these giving me hard time. apache doesn't tell went wrong.
first , last name must 2 simple names , output in lastname, firstname format
my $name = param('name'); if($name =~ {2}) { print "name stored $2, $1<br/><br/>"; } else { print "bad name. enter 2 names, first , last<br/><br/>"; }
password must in order of regexes. begin single upper case character, 2 digits, single space, 2-3 lower case letters, 1 special character (not letter or digit).
my $password = param('password'); if ($password =~ /[a-z]+\d{2}+\s+[a-z]{2,3}+-]\^$/) { print "password $password accepted<br/><br/>"; } else { print "bad password, $password not accepted<br/><br/>"; }
apache doesn't tell went wrong.
first, find apache error log. contain actual error. can't tell is, i'd start /var/log
.
second, debugging code through web server makes things more difficult. you're using cgi.pm can accept arguments on command line debugging.
perl /path/to/your/program name='michael schwern'
second, turn on strict , warnings. point out typos , silly mistakes one...
$ perl -w ~/tmp/test.plx name=foo odd number of elements in anonymous hash @ /users/schwern/tmp/test.plx line 5. bad name. enter 2 names, first , last<br/><br/>
that's this.
$name =~ {2}
that says make anonymous hash key 2 , undefined value. stringify hash(0x7fca01805668)
, use regex. in other words: nonsense.
what you're looking looks 2 words separated spaces.
$name =~ m{^(\w+)\s+(\w+)$};
read perl regex tutorial more info.
Comments
Post a Comment