R
Robert TV
Hi, I'm wondering if there is a simple way to kill (remove) an element from
an array when inside a foreach loop. I can easily add an element to an array
like below:
push(@list, $element);
But when it comes to removing an element, it seems (as far as my research
shows) one would normally use the splice command. This means starting a
counter, when the condition is met, reduce counter by one, then splice it
.... I am looking for something a little more simple like this ("unpush"
syntax not real)
$element = "Mike";
foreach $list (@list) {
if ($list eq $element) {
unpush (this specific @array element)
}
}
Am I dreaming? TIA!
Robert
an array when inside a foreach loop. I can easily add an element to an array
like below:
push(@list, $element);
But when it comes to removing an element, it seems (as far as my research
shows) one would normally use the splice command. This means starting a
counter, when the condition is met, reduce counter by one, then splice it
.... I am looking for something a little more simple like this ("unpush"
syntax not real)
$element = "Mike";
foreach $list (@list) {
if ($list eq $element) {
unpush (this specific @array element)
}
}
Am I dreaming? TIA!
Robert