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

Tagged :
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x