And I suppose if you want to turn it into a one liner this qualifies:#!/usr/bin/perl use strict; # the original array elements my @a = ('1', '2', '3', '4', '5', '6', '7'); # the element we want to remove my $removeThis=3; # container for array elements my $arrayElement; # Temporarily Store the elements we want to keep here my @b; foreach $arrayElement (@a) { # it the element does not match the one we # want to remove we add it to the @b array: if ($arrayElement ne $removeThis) { push(@b, $arrayElement) } } # replace the elements in the @a array with those in # the @b array: @a=@b; # now print it out foreach $arrayElement(@a) {print $arrayElement} #result: #124567
I honestly wouldn't know if there are any disadvantages to this approach. Perhaps others will comment on that.for $i(@a){if($i ne $m){push(@b,$i)}} @a=@b;
In reply to Re: How do I completely remove an element from an array?
by Astounded
in thread How do I completely remove an element from an array?
by vroom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |