Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^4: How do you find duplicates in a string?

by jdporter (Paladin)
on Sep 21, 2006 at 20:17 UTC ( [id://574258]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How do you find duplicates in a string?
in thread How do you find duplicates in a string?

I don't want to know what the dulicates are, I only want to know if there are any...

I'm not sure it's possible to know the latter without also knowing the former. At any rate, any of the solutions shown so far will do the job; just ignore what the actual duplicate values are. For example, my solution can be modified very slightly:

use Scalar::Util qw( looks_like_number ); my %h; $h{$_}++ for split /\t/, $string; my $there_are_duplicates = grep { $h{$_}>1 and !looks_like_number($_) } sort keys %h;

(This exploits the fact that grep returns the list of matching values in list context, and returns the number of matches in scalar context.)

We're building the house of the future together.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found