in reply to Re: Build a list of defined var's
in thread Build a list of defined var's

Well witin my application, i have a reset button. I would like to undef all my var's that are currently defined. Instead of going though each var and undef them, i though it might be eaiser if there was a way to build a list into an array and just irrate though the array and undef them.

Replies are listed 'Best First'.
Re^3: Build a list of defined var's
by merlyn (Sage) on Oct 20, 2009 at 21:40 UTC
    Surely you don't want to reset everything, as that would also reset things like @INC, making your program a little brain-dead. I mean, that's one of the reasons that perldoc -f reset includes the paragraph:
    Resetting "A-Z" is not recommended because you'll wipe out + your @ARGV and @INC arrays and your %ENV hash. Resets only pack +age variables--lexical variables are unaffected, but they clea +n themselves up on scope exit anyway, so you'll probably wan +t to use them instead. See "my".

    The proper way to go about this is to use proper objects in your program, so that you can have a top level object that is associated with a particular session, and everything else hangs off of that. Then, to reset the session, just generate a new session object.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

      So just reload the modules.

Re^3: Build a list of defined var's
by ikegami (Patriarch) on Oct 20, 2009 at 18:51 UTC

    If you want to start with a fresh slate, it's easy. Assuming you haven't changed the current directory or clobbered @ARGV,

    exec $^X, $0, @ARGV

    Note: That won't pass to the new interpreter options that were passed to the first (like -p), but I bet that's not an issue for you.

    Update: Added note.

Re^3: Build a list of defined var's
by zwon (Abbot) on Oct 20, 2009 at 18:41 UTC

    Why not just restart application?