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

Re: wipe out elements in an array

Thread Previous | Thread Next
From:
drieux
Date:
April 25, 2002 17:59
Subject:
Re: wipe out elements in an array
Message ID:
C53C52A8-58B0-11D6-85A2-0030654D3CAE@wetware.com

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:

http://www.wetware.com/drieux/CS/lang/Perl/Beginners/RemoveFromArrayWithSplice.
txt

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...



ciao
drieux

---


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About