http://www.perlmonks.org?node_id=115681


in reply to For - Loop construct 'cheaper' than local variable?
in thread One-shot code critique

You really shouldn't be worryomg about use of reseources at this level.

Focus on good style, readability, ease of coding, major performance issues, and all that other good stuff.

A decent compiler should optimise this sort of construct down to almost nothing (at most a single extra test), which will not be noticeable in the overall performance unless it is in the inside of a very tight loop.

Perl already does some interesting tricks, such as removing if statements from the code and replacing it with and/or, so trying to second guess what the byte code looks like is a waste of time.

The gain you will get in readability and hence reuse, ability to maintain should outweigh any effect in the code.
--
Brovnik

  • Comment on Re: For - Loop construct 'cheaper' than local variable?