Pattern Matching |
Here's a postal code checker written in Perl:
$postalcode = "H3G 1V7"; if ($postalcode =~ s/^([A-Z][0-9][A-Z]) ?([0-9][A-Z][0-9])$/$1$2/) { print $postalcode; } else { print "Invalid postal code: ", $postalcode; }
Pattern Matching |
Here's a postal code checker written in Perl:
$postalcode = "H3G 1V7"; if ($postalcode =~ s/^([A-Z][0-9][A-Z]) ?([0-9][A-Z][0-9])$/$1$2/) { print $postalcode; } else { print "Invalid postal code: ", $postalcode; }
All About Pattern Matching | Sam Wilmott |
Slide 16 of 37 | www.wilmott.ca |