Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
There's more than one way to do things
 
PerlMonks  

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

by CountZero (Chancellor)
on Nov 24, 2012 at 19:08 UTC ( #1005415=note: print w/ replies, xml ) Need Help??


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

Using a regex:

use Modern::Perl; my $randword = join '', ('A'..'Z')[ map rand 26, 1..8 ]; say $randword; say "Make a word with the above characters"; my $word = <>; chomp $word; my $regex = (join '?', sort split '', $randword) . '?'; $word = join '', sort split '', $word; say "Comparing $word with $regex"; if ($word and $word =~ m/^$regex$/i){ say 'OK'; } else { say 'NOT OK'; }

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-04-20 02:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls