This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
x.remove(e);
Returns true if value was in the set, and false if not. The method has no effect if value was not in the set.
my %set;
my @list = ( 'a' .. 'f' );
$set{$_} = 1 for @list;
delete $set{'c'}; # delete specific key
use 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.
@x = grep $e ne $_, @x;
Array is not technically a set since it allows for repeat values. Either you are enforcing uniqueness or you should use a module like Set::Light
x.take(e)
x has type mut HashSet
returns Some(e) if the value was present, None otherwise
returns Some(e) if the value was present, None otherwise
x.remove(e);
x has type mut HashSet
returns true if value was present.
returns true if value was present.