in reply to removing an element without index
Since you didn't provide much detail (or code), I'm making some assumptions on what you're trying to do. The example code below will "remove an element from an array without knowing its index" provided that you know what that element's value is. It may not be elegant or efficient, but it will do what you're wanting.
use strict; my @data = (1,2,3,4,5,6,7,8,9,10); my (@temp) = (@data); # copy array into a temporary array undef @data; # wipeout initial array foreach my $item (@temp) { if ($item !~ m/4/) { # if the element's value is not 4 push @data, ($item); # copy it back into the array } # otherwise do nothing }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: removing an element without index
by GrandFather (Saint) on Aug 10, 2010 at 00:47 UTC | |
by BrowserUk (Patriarch) on Aug 10, 2010 at 01:01 UTC | |
by roboticus (Chancellor) on Aug 10, 2010 at 12:54 UTC | |
by BrowserUk (Patriarch) on Aug 10, 2010 at 12:57 UTC | |
by roboticus (Chancellor) on Aug 10, 2010 at 13:03 UTC | |
|
Re^2: removing an element without index
by AnomalousMonk (Archbishop) on Aug 10, 2010 at 00:01 UTC |