SPUG: undef a list of variables?

Michael Leary leary at nwlink.com
Tue Aug 24 17:06:19 CDT 1999


Thanks to all on the speedy replies; I shoulda mentioned that I've got
references, hashes and arrays to deal with....

here's what I came up with:

foreach my $foo (\(%Structs, %Seq_has, %Thing_look, %Thing_seen, $Lexer, @Real,
$Num_seen, @Data_elements, $Data_index, $VAR1))
{
    if ( ref($foo) eq 'HASH' )
    {
        undef %$foo;
    }
    elsif ( ref($foo) eq 'ARRAY' )
    {
        undef @$foo;
    }
    else
    {
        undef $$foo;
    }
}

not slick, IMO, but it works (comments, please!)

part of the reason for using "use varw qw($yada $blah)" for variables I didn't
real want to have around after the method call in the first place had to do
with warnings about variables becoming unshared in named subroutines.

Anyone dealt with 'unshared' warnings when using 'my' variables and named
subroutines within methods, and come up with something better?

And, yes, I'm under 'use strict'.



jimfl wrote:

> --On Tue, Aug 24, 1999 12:19 PM -0700 Michael Leary <leary at nwlink.com>
> wrote:
>
>      > Anyone know a nifty way to undef a list of variables?  I'm trying to
>      > keep my package namespace clean between method calls.
>
> Something like:
>
>     @clean = (\$foo, \$bar, \$baz, \$ghoti);
>     map {undef $$_} @clean;
>
> --
> Jim Flanagan         Collective Technologies
> jimfl at colltech.com   http://www.colltech.com
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
>         Email to majordomo at pm.org: ACTION spug-list your_address


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list