Unless StripLTSpace() is actually using a prototype to get a reference to $href->{$k} (update: which it then modifies), or the values of the hash may be large, you could probably just make a copy of the value:

for my $k (@required_fields) { my $v = $href->{$k}; StripLTSpace($v); $v or return DIRTY $row, "ERROR: required field $k not present"; }

If you don't want to make a copy, you can use for's aliasing ability, like so:

for my $k (@required_fields) { for my $v ($href->{$k}) { StripLTSpace($v); $v or return DIRTY $row, "ERROR: required field $k not present"; } }

IIRC, the syntax for Perl6 for loops will include the ability to have multiple iterator variables, something similar to:

for my $k, $v (...) {

But I'm not sure how you'd write the ... part. The only thing I can think of now is something involving map that's likely to be more expensive than just creating a copy of the value. *shrug*

Update: Another way to do it:

for my $k (@required_fields) { my $vr = \$href->{$k}; StripLTSpace($$vr); $$vr or return DIRTY $row, "ERROR: required field $k not present"; }

Thinking about it further, however, I find it a bit unlikely that doing two hash look-ups rather than one is actually profiling as a bottleneck in your program. Unless there are extenuating circumstances that you haven't detailed, perhaps you should profile the program to determine exactly where the bottlenecks are occuring.

bbfu
Black flowers blossom
Fearless on my breath


In reply to Re: Will Perl 6 abbreviate this indirection for me? by bbfu
in thread Will Perl 6 abbreviate this indirection for me? by princepawn

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.