Your solution will miss punctuation, whitespace, and international character sets. length is the correct solution.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
:(){ :|:&};:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] |
length() was my first thought as well. Then I read the question, which specifies numbers and letters. So, missing
out on punctuation, whitespace, etc, was exactly what I
intended.
Abigail
| [reply] |
From your first answer, it's not immediately apparent to those of us not familiar with the fact that the tr operator that it returns the number of matched characters.
For those of us who read replies in the hopes of learning something, extra information like this would be very useful...especially, I think, in a case such as your first reply here.
Sure, I spent half an hour (amidst doing other things) reading the perldoc -f tr and then perldoc perlop manpages...And I'm not likely to forget anytime soon that tr returns the number of characters matched...But somehow, the reply of tr/a-zA-Z0-9//
in toto I find wanting...
| [reply] |
This is largely a matter of interpretation. While you are probably correct that length is what the OP really wants, he did state the following:
If a string has less than eight characters (numbers/and or letters) [emphesis added]
Which would support the solution given by Abigail.
| [reply] |