my %set;
my @list = ( 'a' .. 'f' );
$set{$_} = 1for @list;
delete $set{'c'}; # delete specific keyuse v5.20;
delete %set{'a','e'} # delete hash slice
This implementation uses a perl hash %set to act as a set, since keys to a hash must be unique. A list is created to hold the keys, then the hash is initialized from it. The delete operation can delete a specific key. As of version 5.20, you can also delete a hash slice.
my $set = Set::Scalar->new( 'a' .. 'f' );
print"Contents of set:\n";
print $set;
$set->delete('b','e');
print"\nAfter removing elements b and e:\n";
print $set;
Use CPAN Set::Scalar (or Set::Light) to create a set object, which in this example we initialize with letters. We can then use the delete method to delete one or more elements from the set.
my $set = Set::Scalar->new( 'a' .. 'f' );
print "Contents of set:\n";
print $set;
$set->delete('b','e');
print "\nAfter removing elements b and e:\n";
print $set;