in reply to Re: Challenge - Creative Way To Detect Alpha Characters
in thread Challenge - Creative Way To Detect Alpha Characters

Shurely shome mishtake. This returns true for anything other than 0-9, doesn't it? Is that what the OP wanted?

My solution, slightly similar to one of the others:
$range[ chop ] = 1 while $_; # $_ is copy :) grep $_, @range[65..90,97..122];
Did someone mention efficiency (I hope not)?

Replies are listed 'Best First'.
Re^3: Challenge - Creative Way To Detect Alpha Characters
by ambrus (Abbot) on Sep 14, 2004 at 15:40 UTC

    No. The isalpha function I gave returns true only for [a-zA-Z] characters, false on numbers, punctation, international letters, or any other character.

    It seems to give the same results for me than lc ne uc:

    sub isalpha { no warnings "numeric"; my($p) = @_; 0==++$p; } sub hasalpha { my($s) = @_; isalpha(substr($s, 0, 1, "")) and return 1 while length($s); return; }; @t = ("f/2", "-2/", "*+)", "165", "foop", " A="); $\=$/; $,=" "; print grep hasalpha($_), @t; print grep lc ne uc, @t;

    outputs

    f/2 foop A= f/2 foop A=

    This is because if $p is a non-alnum character in the isalpha function, $p++ converts it to a numeric 0 first, than it increases it to 1, so 0==$p++ is false.

Re^3: Challenge - Creative Way To Detect Alpha Characters
by Pragma (Scribe) on Sep 14, 2004 at 18:42 UTC
    Your forgot to ord before you chop.