in reply to Clearing user defined variables

Is there a better way?

Yes it is called scoping your variables and avoiding/limiting the use of global vars. I am amazed you can get 3200 lines to work (presumably one long file) in a stable fashion using globals.

If you wanted to modify your program towards less globals one approach is to use a %globals hash that contains all your globals. When you want to 'reset' the sutem you just reset %globals.

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Clearing user defined variables
by matija (Priest) on Apr 13, 2004 at 07:31 UTC
    He can't "just reset %globals@": the reset takes an argument that is the first letter (or range of first letters) of variable name.

    So if he put in reset 'g', it would reset all variables starting with g, including $g, @great, %google, and if he reset 'globals', it would reset all variables starting with a,b,g,l,o or s.

    IMHO, reset is bad karma.

      Unless I'm missing something, all reset does is undef a gang of variables at once. All that the OPs snippet does is assigns the nothing string to scalars, and the empty set to arrays, so I guess it'd be
      foreach(keys %globals){ if( ref $globals{$_} eq 'ARRAY' ){ @{ $globals{$_} } = (); } else { $globals{$_} = ''; } }

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

      Sorry I was a little unclear. By 'reset' I meant

      %globals = (); # or _init(\%globals);
      or similar not using reset itself. This sort of 'reset' code is found in modules like CGI.pm to reset the globals and is used as a cleanup handler in mod_perl.

      cheers

      tachyon

A reply falls below the community's threshold of quality. You may see it by logging in.