in reply to BEGIN, strict, and variable assignment

Is there a way to avoid having to declare %tests and then assign to %tests on another line?
In a word 'no', or at least, not using lexicals. You could just use a package var however
our %tests = ( ... ); ## or the more compatible, less line lean use vars '%tests'; %tests = ( ... );
Or perhaps
use Test::More tests => do { ... };
HTH

_________
broquaint

Replies are listed 'Best First'.
Re^2: BEGIN, strict, and variable assignment (?)
by tye (Sage) on Mar 03, 2004 at 17:49 UTC

    I don't see how any of these suggestions help in this situation. You still need to put the initialization into a BEGIN block (for the first two suggestions) which means the declaration needs to be separated from the initialization (except in the second case, where they are already separated) or else the variable won't be of any use outside of the BEGIN block.

    So to use any of the suggestions you made, you'd still need the declaration separated from the initialization.

    - tye        

      You're completely right, I really don't know what I was thinking. The above examples would need to be re-written as
      BEGIN { our %tests = ( ... ) } BEGIN { use vars '%tests'; %tests = ( ... ) }
      Which does indeed make them rather redundant suggestions. The suggestion from blokhead in Re: BEGIN, strict, and variable assignment looks to be the most sensible route to take.
      HTH

      _________
      broquaint