Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > set in Perl?

Reply
Thread Tools

set in Perl?

 
 
Davy
Guest
Posts: n/a
 
      08-30-2006
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

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-30-2006
Davy wrote:
> 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

 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      08-30-2006
["Followup-To:" header set to comp.lang.perl.misc.]
On 2006-08-30 13:41, Davy <> wrote:
> 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


--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
 
Reply With Quote
 
Davy
Guest
Posts: n/a
 
      08-31-2006

Paul Lalli wrote:
> Davy wrote:
> > 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!

>

[SNIP]
Hi,

Thanks! Sorry I forgot the hash table's feature.

Best regards,
Davy

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create a node set of elements through C++ code while executing a style sheet and process the created node set. pvssvikas@gmail.com XML 0 01-25-2006 12:48 PM
Treeview questions - how to set set start node and how to catch click event Alan Silver ASP .Net 0 12-21-2005 10:40 AM
How to set up Samsung for a 4x3 set? Feck DVD Video 2 09-15-2004 02:35 AM
java.lang.Set with elements of type java.lang.Set Harald Kirsch Java 4 08-31-2004 10:40 AM
Unable to set focus to textfield in a applet if browser is set to Sun JRE 1.4 Manav Java 0 10-15-2003 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57