set in Perl?

D

Davy

Hi all,

I used to use set (only contain one identical thing in one set) in
C++'s STL. I found set very useful that you can do something like
intersection. Is there something similar in Perl? Thanks!

Best regards,
Dav
 
P

Paul Lalli

Davy said:
I used to use set (only contain one identical thing in one set) in
C++'s STL. I found set very useful that you can do something like
intersection. Is there something similar in Perl? Thanks!

You generally want to use a hash. The keys of a hash are distinct by
definition. If you tell us what your actual goal or problem is, we can
give you more specific assistance...

You may also be interested in:
perldoc -q intersection

my %unique;
for (qw/foo bar baz bar foo baz baz) {
$unique{$_} ++;
}
my @set = keys %unique;

# @set will contain three elements - foo, bar, and baz (in some random
order)

Paul Lalli
 
P

Peter J. Holzer

["Followup-To:" header set to comp.lang.perl.misc.]
I used to use set (only contain one identical thing in one set) in
C++'s STL. I found set very useful that you can do something like
intersection. Is there something similar in Perl? Thanks!

Have you tried searching for "set" on CPAN? Set::Scalar is one of the
first hits I get.

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top