http://qs321.pair.com?node_id=582212


in reply to My 'perldar' tells me there is a 'better' solution for this list operation

Hi OfficeLinebacker,

In order to reduce the 'noise factor' of your array definitions, you could also construct each as follows:

#!/usr/bin/perl use warnings; use strict; my ( @l1, @l2 ); @l1 = qw(Date IndexID Maturity OnTheRun CompositePrice CompositeSpread ModelPrice ModelSpread Depth Heat); @l2 = qw(OnTheRun CompositePrice CompositeSpread Depth); # More code here...


By declaring your variables, arrays, hashes, etc. at an earlier stage in the program, it reduces, in my experience, a portion of the frustration inherently present in the debugging process.

Hope this helps,

~Katie
  • Comment on Re: My 'perldar' tells me there is a 'better' solution for this list operation
  • Download Code

Replies are listed 'Best First'.
Re^2: My 'perldar' tells me there is a 'better' solution for this list operation
by Jenda (Abbot) on Nov 04, 2006 at 17:20 UTC

    I don't think you gain anything this way. Except that you exercise your fingers more. And I don't think it's good to predeclare your variables. You should keep the scope of all variables as small as posible, declaring them only as you intend to start using them. Sometimes it's even good to introduce a block into the code just so that you could specify the scope of a variable, if you want to use it just in those ten lines and not anywhere else. Everything is IMHO of course.