undeclaring multiple arrays

Discussion in 'Perl Misc' started by Aaron, Aug 21, 2003.

  1. Aaron

    Aaron Guest

    I've looked on deja a little but couldn't find a definite answer. I
    created an array of hashes to store a lot of data. I have everything
    declared as locally as possible with MYs but I'm still taking up too
    much memory.

    Here's a shorted version of my code:

    foreach $key (sort { $top10talkTemp{$b} <=> $top10talkTemp{$a} }
    keys(%top10talkTemp)) {

    foreach (@{$source{$key}}) {
    #Stuff in here
    }

    @{$source{$key}} = undef;
    }

    The @{%hash} is new to me. Is setting @{$source{$key}} = undef the
    best way to clear the memory space, or can I do @{%source} = undef
    after the foreach loop? Or is there even a better method?

    Thanks in advance,
    Aaron
     
    Aaron, Aug 21, 2003
    #1
    1. Advertising

  2. Aaron wrote:
    >
    > I've looked on deja a little but couldn't find a definite answer. I
    > created an array of hashes to store a lot of data. I have everything
    > declared as locally as possible with MYs but I'm still taking up too
    > much memory.
    >
    > Here's a shorted version of my code:
    >
    > foreach $key (sort { $top10talkTemp{$b} <=> $top10talkTemp{$a} }
    > keys(%top10talkTemp)) {
    >
    > foreach (@{$source{$key}}) {
    > #Stuff in here
    > }
    >
    > @{$source{$key}} = undef;
    > }
    >
    > The @{%hash} is new to me. Is setting @{$source{$key}} = undef the
    > best way to clear the memory space, or can I do @{%source} = undef
    > after the foreach loop? Or is there even a better method?


    If you just want to delete the key then use delete:

    delete $source{$key};

    However if you want to keep the key and just clear the array for that
    key:

    @{$source{$key}} = ();


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Aug 21, 2003
    #2
    1. Advertising

  3. Aaron <> wrote:
    A> I've looked on deja a little but couldn't find a definite answer. I
    A> created an array of hashes to store a lot of data. I have everything
    A> declared as locally as possible with MYs but I'm still taking up too
    A> much memory.

    A> Here's a shorted version of my code:

    A> foreach $key (sort { $top10talkTemp{$b} <=> $top10talkTemp{$a} }
    A> keys(%top10talkTemp)) {

    A> foreach (@{$source{$key}}) {
    A> #Stuff in here
    A> }

    A> @{$source{$key}} = undef;
    A> }

    A> The @{%hash} is new to me. Is setting @{$source{$key}} = undef the
    A> best way to clear the memory space, or can I do @{%source} = undef
    A> after the foreach loop? Or is there even a better method?

    Have you read:

    $ perldoc -q memory

    Regards,

    Nicholas

    --
    "Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
    "Meanings are another story." http://www.ifas.org/wa/glossolalia.html
     
    Nicholas Dronen, Aug 21, 2003
    #3
  4. Aaron

    Aaron Guest

    Thanks to you both. The information provided helped.
     
    Aaron, Aug 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman
    Replies:
    5
    Views:
    30,917
    Chris Smith
    Jun 17, 2004
  2. Bill Reyn
    Replies:
    3
    Views:
    2,343
    Bob Hairgrove
    Jun 22, 2004
  3. Mantorok Redgormor

    initializing arrays of arrays

    Mantorok Redgormor, Sep 10, 2003, in forum: C Programming
    Replies:
    4
    Views:
    590
  4. kelvSYC

    Arrays and Pointers to Arrays

    kelvSYC, Sep 26, 2003, in forum: C Programming
    Replies:
    2
    Views:
    407
  5. Philipp
    Replies:
    21
    Views:
    1,190
    Philipp
    Jan 20, 2009
Loading...

Share This Page