In Perl, you can use the scalar
context to check if a Set is not empty.
In this example,
scalar
operator in scalar context on the Set to determine its size.# Initialize a Set
my @set = (1, 2, 3); # Or my @set;
# Check if Set is not empty
if (scalar @set) {
print 'The Set is not empty\n';
} else {
print 'The Set is empty\n';
}
The Set is not empty
In this example,
scalar
operator in scalar context on the Set to determine its size.# Initialize an empty Set
my @empty_set;
# Check if Empty Set is not empty
if (scalar @empty_set) {
print 'The Set is not empty\n';
} else {
print 'The Set is empty\n';
}
The Set is empty
In this tutorial, we learned How to check if a Set is Not Empty in Perl language with well detailed examples.