Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Re: Re: undef'ing @arrays caveat

by Juerd (Abbot)
on Apr 20, 2002 at 23:01 UTC ( #160818=note: print w/replies, xml ) Need Help??

in reply to Re: Re: undef'ing @arrays caveat
in thread undef'ing @arrays caveat

True, and in fact if you undef @array the effect is identical.

Try using Devel::Peek. undef @array sets MAX to -1, @array = () does not. Or use Benchmark and find out that undef @array is about twice as fast. The effect is the same, but internally, there's something entirely different going on.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re(4): undef'ing @arrays caveat
by dmmiller2k (Chaplain) on Apr 20, 2002 at 23:12 UTC

    Granted. But besides the speed issue, the result is effectively the same.

    In the case of undef @array, @array does not actually get undefined (i.e., it still exists), just emptied, however more efficiently than with @array = ().

      @array does not actually get undefined

      undef can only un-define scalars, because only scalars can be not-defined. Hashes and arrays are emptied, subs and globs are destroyed. I think the manual is not clear enough about this.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160818]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2023-09-22 04:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found