package Abh::SimpleSet; sub new { my $self = {}; bless $self; return $self; } sub add { my ($self, $item) = @_; $self{$item} = undef; } sub remove { my ($self, $item) = @_; delete($self{$item}); } sub contains { my ($self, $item) = @_; return exists($self{$item}); } sub to_string { my $self = shift; return $class, "(" . join (", ", keys %self) . ")"; } sub union { my ($self, $otherSet) = @_; foreach $key (keys %otherSet) { $self{$key} = undef; } } # Must return true 1; #### use Abh::SimpleSet; $set1 = Abh::SimpleSet->new(); $set2 = Abh::SimpleSet->new(); $set1->add("a"); $set1->add("b"); $set1->add("c"); print "Set 1: " . $set1->to_string() . "\n"; $set2->add("d"); $set2->add("e"); $set2->add("f"); print "Set 2: " . $set2->to_string() . "\n"; #### Set 1: (a, b, c) Set 2: (e, f, a, b, c, d)