To remove a specific item from a set in Perl, you can use the delete function to delete the item from the set.
In this example,
%number_set
using a hash in Perl, which contains integer values 1
, 2
, 3
, 4
, and 5
.delete
function with %number_set
and the item key 3
to remove the item from the set.%number_set
to see the removed item.%number_set = (1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1);
delete $number_set{3};
print "@{[keys %number_set]}\n";
1 2 4 5
In this example,
%string_set
using a hash in Perl, which contains string values 'apple'
, 'banana'
, 'cherry'
, 'date'
, and 'grape'
.delete
function with %string_set
and the item key 'cherry'
to remove the item from the set.%string_set
to see the removed item.%string_set = ('apple' => 1, 'banana' => 1, 'cherry' => 1, 'date' => 1, 'grape' => 1);
delete $string_set{'cherry'};
print "@{[keys %string_set]}\n";
apple banana date grape
In this tutorial, we learned How to Remove Specific Item from a Set in Perl language with well detailed examples.