I couldn't help but turn Quantum::Superpositions loose on this problem. The 'any()' function is the key to a creative solution. The idea is to compare the return value of 'any( $test_string )' with the return value of 'any( 'A'..'Z', 'a'..'z' )'. If the comparison results in equality, you've got alphas in your test string. Here's an example:
use strict;
use warnings;
use Quantum::Superpositions;
{
my $superstring = any( 'A'..'Z', 'a'..'z' );
sub has_alpha {
return $superstring eq any(
map chr, unpack 'C*', shift
);
}
}
while ( <DATA> ) {
chomp;
print "$_\t=>\thas alphas.\n" if has_alpha($_);
}
__DATA__
12345
abcdef12345
$@!^%^&(*aB&#@
1A2B3C4D
!@#$*&()
I love that module. theDamian++. Of course if you want to implement this solution in another language, you'll have to port his module too. ;)
Updated: Streamlined the code a bit, and eliminated need for split.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|