undeclaring multiple arrays

A

Aaron

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
 
J

John W. Krahn

Aaron said:
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
 
N

Nicholas Dronen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top