Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Challenge - Creative Way To Detect Alpha Characters

by Anonymous Monk
on Sep 13, 2004 at 22:32 UTC ( [id://390684]=note: print w/replies, xml ) Need Help??


in reply to Challenge - Creative Way To Detect Alpha Characters

Okay, I think this should work: #!/usr/bin/perl $string = $ARGV[0]; for(split(//,$string)) { if(($_ * $_ == 0) && $_ ne '0') { print "alpha: $string\n"; exit(0); } } print "numeric: $string\n"; jkauffman
  • Comment on Re: Challenge - Creative Way To Detect Alpha Characters

Replies are listed 'Best First'.
Re^2: Challenge - Creative Way To Detect Alpha Characters
by Anonymous Monk on Sep 13, 2004 at 22:37 UTC

    Sorry, this is my first time posting here... let me try that again:

    #!/usr/bin/perl $string = $ARGV[0]; for(split(//,$string)) { if(($_ * $_ == 0) && $_ ne '0') { print "alpha: $string\n"; exit(0); } } print "numeric: $string\n";

    jkauffman

      jkauffman,

      Unfortunately this code fails for special chars (@,#,$,%...), if you $_++, the the special chars=>1, but alphas increment. If you look at my code above you will see that our attempts are similar, $_**2 is the same as $_ * $_, and does remove the the numbers (except 0) again this is why you would use $_++, adding that first takes care of the zero. I am just not sure if my code above filters all special chars.

      Good attempt, we were thinking similar ;)

      Cameron

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found