develooper Front page | perl.beginners | Postings from April 2002

Re: wipe out elements in an array

Thread Previous | Thread Next
April 25, 2002 17:59
Re: wipe out elements in an array
Message ID:

On Thursday, April 25, 2002, at 04:58 , Bryan R Harris wrote:

> My guess (this is just an example):
> @myarray = (1,2,3,4,5,6,7,8,9,10);
> foreach (@myarray) { if ($_ == 3 || $_ == 5) { undef($_); } }

what you want to look at is

	perldoc -f splice

one way to hack a solution here would be:

The funk that I ran into and did not expect was that my
simplistic first idea is the standard

	while ( $count < $len ) {
		#someJazz with Splice

but that really is not as simple - since well, you
are shrinking the size of the array - so you have
to shrink the $len - and NOT increment the $count,
because now $array[$count] is a Completely new
element you haven't seen before...



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About