Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regex to compare (if) two strings (Uniquely - I will explain inside)

by Kenosis (Priest)
on Nov 24, 2012 at 18:29 UTC ( #1005411=note: print w/ replies, xml ) Need Help??


in reply to Regex to compare (if) two strings (Uniquely - I will explain inside)

Gotta validate the inputted word by checking that it indeed consists of the chars in $random_string.

Perhaps I'm misunderstanding you, but this sounds like you want to validate that the two sets of string characters are equal (the 'compare uniquely')--not that the two strings are equal. If this is the case, the following is an option:

use strict; use warnings; my $word = 'FHDJSKAL'; my $random_string = 'ALSKDJFH'; if ([sort ("\U$word" =~ /./g)] ~~ [sort ("\U$random_string" =~ /./g)]) + { print "Good word.\n"; } else { print "Try again.\n"; print "\n"; }

Hope this helps!

Update: Replaced the hash solution with one using the smart operator (~~), as the former didn't match properly.


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-09-23 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls