Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Re: Find duplicate chars in a string

by CheeseLord (Deacon)
on Oct 14, 2001 at 09:01 UTC ( [id://118738]=note: print w/replies, xml ) Need Help??


in reply to Re: Find duplicate chars in a string
in thread Find duplicate chars in a string

Um... that code doesn't compile, nor does it do the same thing as the original code. This is my version (it could use whatever error checking you might want on the user-supplied alphabet, though):

sub has_dup_letters { local $_ = lc shift; my $alpha = @_ ? shift : 'a-z'; eval "tr/$alpha//cd"; my (%dups, $total); $dups{$_}++ and $total++ for split //; return $total; }

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re: Re: Find duplicate chars in a string
by merlyn (Sage) on Oct 14, 2001 at 19:10 UTC
    eval "tr/$alpha//cd";
    That can be evil if $alpha contains a slash or is untrusted. To do that tr right requires some really careful thinking.

    That's why I conveniently ignored all but the basic specification. {grin}

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found