Adam Turoff on Wed, 20 Feb 2002 16:12:15 -0500 |
----- Forwarded message ----- Subject: RE: help! (fwd) Date: Wed, 20 Feb 2002 11:55:09 -0500 From: "Sean Cannon" <scannon@cc3.com> To: <mjd-per-pm@plover.com>, <bz@CrestecDigital.com> Cc: <phl@lists.pm.org> I get the strong impression you completely missed what the person originally posing the question is trying to do. They did not ask about validation of Canuck postcodes. They asked about determining whether the code was within a certain range or not. It can be safely assumed that either a) they are already validating with no problem or b) they are going to end up asking that later. Next, it's also easily assumable that the 'example code' they asked was not intended to be perl code but, rather, an example of what they are trying to do. UNless you have a perl compiler in your head, you should have no problem readin what they are trying to do. Third, unless they are stripping out the space before comparison, that's one of the major flaws with their approach. Fourth, they should be using eq, not ==. That's the real bug. Numerically, all of these zip codes, since they begin with a letter, will == 0, and 0 == 0. -- Sean Cannon > -----Original Message----- > From: owner-phl@lists.pm.org > [mailto:owner-phl@lists.pm.org]On Behalf Of > Adam Turoff > Sent: Wednesday, February 20, 2002 11:36 AM > To: phl@lists.pm.org > Subject: Re: help! (fwd) > > > ----- Forwarded message ----- > To: "William G. Zappasodi" <bz@CrestecDigital.com> > Cc: phl@lists.pm.org > From: mjd-per-pm@plover.com > Subject: Re: help! (fwd) > In-reply-to: Your message of "Wed, 20 Feb 2002 11:16:02 EST." > <20020220161602.GB8993@panix.com> > Date: Wed, 20 Feb 2002 11:33:31 -0500 > Sender: mjd@plover.com > > > > Can anyone help please. I have a routine that is supposed > to capture a zip > > code if it falls in a range. It works fine with US zips, > but not Canadian. > > Seems to capture any range for CA. > > You have a lot of bugs here. > > One is that you have 'zip' where you should have '$zip'. maybe that's > your main problem. > > Another problem you have is that you're going to reject Canadian > postal codes that are in Alberta or British Columbia, since they begin > with T and V, and you don't accept that. > > A big problem is that in_range() is totally inappropriate for Canadian > postal codes anyway. For example, > > in_range($zip, 'A1A1A1', 'S9Z9Z9') > > will succeed when $zip is 'A1Z!$&', but this is not a valid Canadian > postal code. > > I strongly recommend that you abandon this approach completely, and > use: > > if ($country eq CA > && $zip =~ /^ > [ABCEGHJKLMNPRSTVXY] \d [ABCEGHJKLMNPRSTVWXYZ] > \s+ > \d [ABCEGHJKLMNPRSTVWXYZ] \d > $/x) { > # postal code is good > } > > Note that this requires a space between the two halves of the code; > according to Canada Post, this space is mandatory. To make it > optional, change \s+ to \s*. > > I hope this is helpful. > > ----- End forwarded message ----- > **Majordomo list services provided by PANIX > <URL:http://www.panix.com>** > **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org** > ----- End forwarded message ----- **Majordomo list services provided by PANIX <URL:http://www.panix.com>** **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|