The first part:

for my $c (1..$data->{n1}) {

Will not be faster by allocating to an intermediate $n1 variable. It may even be a couple of nanoseconds slower.

The second part:

$data->{"exclude-$c-$_"} = 'yes' for 1..$data->{n2};

May be very slightly faster if you assign an intermediate $n2 variable before the outer loop because it prevents a hash lookup for each iteration of the outer loop. However with your n1 being "like 10 or less", this is not likely to make any practical difference in speed. If you were dealing with millions of iterations of the outer loop, it might be worth optimizing.


In reply to Re: does a hash element as a loop parameter cause significant slowdown? by tobyink
in thread does a hash element as a loop parameter cause significant slowdown? by misterperl

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.