http://www.perlmonks.org?node_id=1005406


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

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

  • Comment on Re: Regex to compare (if) two strings (Uniquely - I will explain inside)
  • Download Code

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
    I really like the way you are generating the random word; however, my understanding is that sub-sets of letters may be used to make words and your comparison at the end will only work if all letters are used when the user creates a word.

      Looking at the OP a second time:

      Input a word from user (that they make FROM the 8 random chars such as in Scrabble).

      You are probably right. Mea culpa.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong