Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Challenge - Creative Way To Detect Alpha Characters

by parv (Parson)
on Sep 14, 2004 at 21:37 UTC ( [id://390987]=note: print w/replies, xml ) Need Help??


in reply to Challenge - Creative Way To Detect Alpha Characters

To all those, including myself, who are using, or had used, two lists (a..z , A..Z): Why not just convert the string to either upper or lower case before working on it so that only 26-element list, instead of 52, would be needed?

In my case ... i didn't even think of it until i was working on the Rexx solution. To repent, below is perl translation....

sub has_alpha { my ($string) = @_; return unless length $string; $string = lc $string; my ($start , $stop) = qw/a z/; while ($start le $stop) { index($string , $start++) != -1 and return 1; } return; }

Replies are listed 'Best First'.
Re^2: Challenge - Creative Way To Detect Alpha Characters
by BrowserUk (Patriarch) on Sep 14, 2004 at 21:50 UTC

    You'd then have to scan the list twice. Once to convert, once to compare.

    The original (and best) solution did 3 passes by both upping and lowing the string and comparing, but all three passes where in C rather than perl, so fast.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

      (I removed my comment about the first statement of BrowserUK about which i am still thinking.)

      Yes, you are quite right, BrowserUK, on the point of original solution being the best; it is simple, short, and to the point.

Log In?
Username:
Password:

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

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

    No recent polls found