in reply to Regex to compare (if) two strings (Uniquely - I will explain inside)
Sort the letters in both strings and compare the results:
$randword = join'', ('A'..'Z')[ map rand 26, 1..8 ];; print $randword;; LDAZAJSA chomp( $input = <STDIN> );; AAADJLSZ print join('', sort split '', $randword ) eq join( '', sort split '', +$input ) ? 'Ok' : 'Bad';; Ok
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to compare (if) two strings (Uniquely - I will explain inside)
by frozenwithjoy (Priest) on Nov 24, 2012 at 18:29 UTC | |
by BrowserUk (Patriarch) on Nov 24, 2012 at 20:02 UTC |