<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18928">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV><FONT size=2 face=Arial><FONT size=2 face=Arial>Modifying the array while
iterating through the array is usually something to be avoided when
writing clear code. Don't do it.</FONT></FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV>
<DIV><FONT size=2 face=Arial>What would you expect the foreach function to
return when you are modifying the list under its feet?</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>You may also want to look at using the grep and map
functions.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT><BR>Indy Singh<BR>IndigoSTAR Software -- <A
href="http://www.indigostar.com">www.indigostar.com</A><BR></DIV></DIV></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=fulko.hew@gmail.com href="mailto:fulko.hew@gmail.com">Fulko Hew</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=tpm@to.pm.org
href="mailto:tpm@to.pm.org">TPM</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, June 30, 2010 11:06
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [tpm] how to delete array
entries en-passant</DIV>
<DIV><BR></DIV><SPAN style="FONT-FAMILY: courier new,monospace">As the subject
line asks...</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">what I'd like to do is something
like</SPAN><BR style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">foreach (@array)
{<BR> if (condition) {<BR> splice
@array, this_entry, 1;<BR>
next;<BR> }<BR> do processing on this entry;
</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">}</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace"><BR>@array now contains a sub-set
of the original<BR>that I can now further process<BR></SPAN><BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">'delete' might work, but the words
say delete on arrays is deprecated</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">and it still doesn't give me the
delete 'this' entry concept, because<BR>it too works on an index.</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">I'd like to do it without creating
another array, because I like<BR>'premature optimizations'</SPAN><SPAN
style="FONT-FAMILY: courier new,monospace"> and because I think it would make
the<BR>code more readable.</SPAN> :-)<BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">TIA</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><SPAN
style="FONT-FAMILY: courier new,monospace">Fulko</SPAN><BR
style="FONT-FAMILY: courier new,monospace"><BR
style="FONT-FAMILY: courier new,monospace">
<P>
<HR>
<P></P>_______________________________________________<BR>toronto-pm mailing
list<BR>toronto-pm@pm.org<BR>http://mail.pm.org/mailman/listinfo/toronto-pm<BR></BLOCKQUOTE></BODY></HTML>