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.