I stand corrected. You are correct on your points. Sorry for the accusation. For those interested, here is the code and results from benchmarking.
code:
use Benchmark; sub foreach1000() { my @x = (1..1000); foreach(@x) { my $z = $_; } } sub for1000() { my @x = (1..1000); for(my $y = 0; $y < scalar(@x); $y++) { my $z = $x[$y]; } } sub foreach10000() { my @x = (1..10000); foreach(@x) { my $z = $_; } } sub for10000() { my @x = (1..10000); for(my $y = 0; $y < scalar(@x); $y++) { my $z = $x[$y]; } } timethese( 10000, { for1000 => 'for1000()', foreach1000 => 'foreach100 +0()', for10000 => 'for10000()', foreach10000 => 'foreach10000()' });
results:
Benchmark: timing 10000 iterations of for1000, for10000, foreach1000, +foreach10000... for1000: 59 wallclock secs (53.75 usr + 0.03 sys = 53.78 CPU) @ 18 +5.95/s (n=10000) for10000: 676 wallclock secs (537.40 usr + 0.23 sys = 537.63 CPU) @ + 18.60/s (n=10000) foreach1000: 33 wallclock secs (24.67 usr + 0.00 sys = 24.67 CPU) @ 4 +05.27/s (n=10000) foreach10000: 293 wallclock secs (250.74 usr + 0.21 sys = 250.95 CPU) + @ 39.85/s (n=10000)

In reply to RE: Buzzcutbuddha(I Stand Corrected): C Style For and Foreach The Same by buzzcutbuddha
in thread Finding the length of an array of arrays by target

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.