Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by ambrus (Abbot)
on Sep 14, 2004 at 15:40 UTC ( [id://390880]=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-25 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found