Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: string comparison

by davidj (Priest)
on May 27, 2005 at 07:22 UTC ( [id://460966]=note: print w/replies, xml ) Need Help??


in reply to string comparison

Assuming that strings "match" if they have the same number of comma delimited words, the following will do the trick:

#!/usr/bin/perl use strict; my (%str1, %str2); my $str1 = "~cake,pastry"; my $str2 = "pastry,~cake"; my @str1 = split(",", $str1); my @str2 = split(",", $str2); map { $str1{$_}++ } @str1; map { $str2{$_}++ } @str2; foreach $key (keys %str1) { print "not equal\n" if $str1{$key} != $str2{$key}; }
davidj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found