Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Perl function to remove any element using value validation

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

Rajesh Kumar
Follow me
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x