[EMAIL PROTECTED] wrote:
> Philip, while I always view your posts as a source of illumination,
Why, thank you :-). That's nice to hear.
> I do want to point out one error in your reply to this person.
> You wrote:
>
> >> $good_tel_number = 1 if($tel_number =~ /^\d{10}$/);
> >
> > (Aside from the fact that your code doesn't match foreign
> telephone numbers
> > because it needs exactly ten, it'll also match
> > "this1is2not3a4telephone5number6in7any8country9I0know"
> because that string
> > contains 10 digits....)
>
> But clearly this is not the case.
Sorry, my fault -- unclear antecedent. What I meant was that "your code will also match [big ugly string]"; that is, "it" == "your code", not "it" == "this fragment I'm giving you". And the original code *will* match anything containing ten digits *anywhere* in the string, regardless of any other garbage there might be.
> So, while I agree with all your other points, I'll disagree on this
> one. ^\d{10}$ will match only those cases where there are precisely
> 10 numbers and nothing else on the line.
That was my intent. After all, when I dial, I dial numbers and not letters or punctuation, etc. However, I didn't think about the possibility of writing numbers with embedded spaces or punctuation such as (800) 555-1212. But even if you just want to check for exactly ten digits (ignoring other characters), I would consider "$good_tel_number = 1 if $tel_number =~ tr/0-9// == 10" to be better than the ghastly hack in the original code -- using tr/// to count the number of digits.
> This of course fails miserably in many legal cases, not only overseas
> but even in the USA.
Define "legal", and you have a regex which will match your phone number :-).
> As you said so euphemistically, the submitted code is a ghastly hack.
> Only in a web-programming book would an author be allowed to get away
> with offering such awful code.
I would consider not even then. There's no excuse for bad code. Similarly, if you're writing a book about Perl and CGI, your HTML code should still be correct.
Larry says that it's official OK to talk baby-talk in Perl, and TMTOWTDI -- but I (and many other Perlers) think that some ways are better than others. And some ways are just horrible.
Cheers,
Philip