Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005411]
[Lady_Aleena]: I don't want to have to do: alpha_menu($hash, undef, $type);
[Lady_Aleena]: Or what Discipulus said.
[shmem]: Lady_Aleena: geany supports ctags.
[Discipulus]: a good compromise can be my ($need, $opts_ref) = @_ a scalar and an hash reference
[Discipulus]: see you monks!
[Lady_Aleena]: shmem, let me get this sub rewritten, then I will look into how to use ctags in geany. Deal? 8)
[shmem]: Discipulus: yeah, that might eventually prepare the path for OO ;-)
[Lady_Aleena]: See you, Discipulus.
[shmem]: Lady_Aleena: that's up to you. I only wanted to show you a path that might be more comforting than command line grep ;-)
[Lady_Aleena]: shmem, I don't think any of my modules could be converted to OO. They are too procedural.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-27 12:25 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (506 votes). Check out past polls.