in reply to how to clear an array

@tmp = () makes @tmp an array with zero elements. undef @tmp undefines @tmp. Check the output from:

my @foo = qw(foo bar baz); @foo = (); print "\@foo is defined.\n" if defined @foo; my @bar = qw(foo bar baz); undef @bar; print "\@bar is defined.\n" if defined @bar;

Owl looked at him, and wondered whether to push him off the tree; but, feeling that he could always do it afterwards, he tried once more to find out what they were talking about.

Replies are listed 'Best First'.
Re^2: how to clear an array
by Anonymous Monk on Feb 25, 2006 at 13:41 UTC
    That may work fine on Perl4 but:
    perldoc -f defined [snip] Use of "defined" on aggregates (hashes and arrays) is deprecated +.
    So don't do that. :-)

      I wouldn't use something like that in production code, but it's good to know that there's a reason beyond my personality flaws. ;)

      Owl looked at him, and wondered whether to push him off the tree; but, feeling that he could always do it afterwards, he tried once more to find out what they were talking about.