in reply to Re: Regexp for alphabetical order match within the string
in thread Regexp for alphabetical order match within the string
You can avoid the sort for an O(N) solution:
sub is_alphabetical { my @c = split //, shift; ord($c[$_]) >= ord($c[$_ - 1]) or return 0 for 1 .. $#c; return 1; }
Update: Yes, my use of ord() is unnecessary. Thanks tlhf++.
Edit: Added a missing my.
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Regexp for alphabetical order match within the string
by tlhf (Scribe) on Oct 30, 2003 at 19:45 UTC | |
|
Re: Re: Re: Regexp for alphabetical order match within the string
by pg (Canon) on Oct 30, 2003 at 20:37 UTC | |
by Roy Johnson (Monsignor) on Oct 30, 2003 at 21:32 UTC | |
by sauoq (Abbot) on Oct 30, 2003 at 21:00 UTC |