<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.0.5">
</HEAD>
<BODY>
# $numberOfElements = scalar @ary;<BR>
# $lastArrayIndex = $#ary;<BR>
<BR>
foreach $idx (0..$#ary) {<BR>
&nbsp; $element = $ary[$idx];<BR>
&nbsp; print &quot;$element is at index $idx in \$ary\n&quot;;<BR>
}<BR>
<BR>
tell us a little more about your data and your hardware environment, and maybe we can help w/ performance. it shouldn't take days to iterate an array; i guess it's possible that you've got massive swap space and you're seeing nothing but i/o thrashing, but that's not likely either.<BR>
<BR>
<BR>
<BR>
On Thu, 2003-07-10 at 08:00, Brian Michalk wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373"><I>Let's say I have a sparse array:
$ary[100]=1;
$ary[100000]=2;
$ary[1000000]=3;

Now, I want to iterate over the array, either from lowest to highest array
index, and still retain the index of the element returned.  How do I do
that?

foreach $elt (@ary) {
        $some_value = $elt;
        $the_index = ????????;                        # how do I get this information?
}


This algorithm is chewing up CPU time, causing the process to take days to
complete... the dataset is several gigabytes large.

Using a hash, and sorting the keys will not give me a performance benefit.

_______________________________________________
Austin mailing list
Austin@mail.pm.org</FONT>
<A HREF="http://mail.pm.org/mailman/listinfo/austin"><U>http://mail.pm.org/mailman/listinfo/austin</U></I></A></PRE>
</BLOCKQUOTE>
</BODY>
</HTML>