Use splice or grep. If you decide to use splice, either go through the array backwards, or do not increment your index counter when you delete an array item, or you'll skip one in your test.
grep would be easier:
@filtered = grep { $_ != 0 } @l;
| [reply] [d/l] |
You remove elements from arrays with splice. A short excerpt from perldoc -f splice:
- splice ARRAY,OFFSET,LENGTH,LIST
- Removes the elements designated by OFFSET and LENGTH from an array, and replaces them with the elements of LIST, if any.
push, pop, shift, and unshift can all be expressed as a splice. In your case, you want to delete one entry so specify its index as OFFSET and 1 for LENGTH. You aren't replacing this range with anything so leave off LIST. So splice @1,$i,1 (are you really using numbers for your array names? that sounds kind of odd).
Also, since in your example you want to remove the last entry from the list, you could use pop.
---
print map { my ($m)=1<<hex($_)&11?' ':'';
$m.=substr('AHJPacehklnorstu',hex($_),1) }
split //,'2fde0abe76c36c914586c';
| [reply] [d/l] [select] |
Have a look at the splice function in the perlfunc documentation page.
In your case, splice(@1, $#1, 1) will do the trick.
Hope this helps, -gjb-
| [reply] [d/l] [select] |