Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > undeclaring multiple arrays

Reply
Thread Tools

undeclaring multiple arrays

 
 
Aaron
Guest
Posts: n/a
 
      08-21-2003
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
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      08-21-2003
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
 
Reply With Quote
 
 
 
 
Nicholas Dronen
Guest
Posts: n/a
 
      08-21-2003
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
 
Reply With Quote
 
Aaron
Guest
Posts: n/a
 
      08-24-2003
Thanks to you both. The information provided helped.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
char arrays and integer arrays... why the difference? Bill Reyn C++ 3 06-22-2004 12:01 PM
Arrays.asList() returning java.util.Arrays$ArrayList Alexandra Stehman Java 5 06-17-2004 06:04 PM
Arrays and Pointers to Arrays kelvSYC C Programming 2 09-26-2003 06:52 AM
initializing arrays of arrays Mantorok Redgormor C Programming 4 09-11-2003 02:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57