rajeshkumar created the topic: perl function to remove any element using value validation
perl function to remove any element using value validation
Not Working –
my @items = (rajesh1, rajesh2,rajesh3,rajes4,rajesh5,rajesh7)
my $index = 0;
for my $value (@items) {
print "testing $value\n";
if ( $value == "rajesh1" or $value == "rajesh2" or $value == "rajesh3") {
print "removed value $value\n";
splice @items, $index, 1;
}
$index++;
}
print "@items"
Not Working
my @items = (rajesh1, rajesh2,rajesh3,rajes4,rajesh5,rajesh7)
my $element_omitted = "rajesh1";
@items = grep { $_ != $element_omitted } @items;
print "Value of @items";
Trying this now.
my $index = 0;
while ($index <= $#items ) {
my $value = $items[$index];
print "testing $value\n";
if ( $value == 1 or $value == 3 ) {
print "removed value $value\n";
splice @items, $index, 1;
} else {
$index++;
}
}
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024