Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Challenge - Creative Way To Detect Alpha Characters

by Jasper (Chaplain)
on Sep 14, 2004 at 10:17 UTC ( [id://390783]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://390783]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found