Ask a Question related to PERL Miscellaneous, Design and Development.
-
S. Heiling #1
Big hash question
I have a very large hash inside a script.
The $values of the $keys can be very large.
When the script runs, it takes a long time to load the hash.
And this eats up memory...really fast!
At least I'm assuming that's what it's doing.
My question is, is there a way to stop this?
How can I keep the whole hash from loading at startup?
while ( ($key, $value) = each %hash) {
# This is what I'm using for the hash
}
Thanks.
S. Heiling Guest
-
Simple Hash Question / NEVER MIND
DOH ..... DOH ..... NEVER MIND, user error ( <- gun to head) DOH ..... DOH ..... DOH ..... ... -
Simple Hash Question
Hi .... I have a hash defined as my %flag3 = ( A => "DBSpace backup thread", B => "Begin work", C => "Commiting/committed", H => "Heuristic... -
[PHP-DEV] hash table question
For my upcoming improvement of interbase.c, which features asynchronous handling of events posted in the database, I need to maintain a per-link... -
Another reference question (hash of hash references)
beginners, I am trying to build a hash of hash references. My problem is that I need to be able to add a key/value pair to the internal hashes...... -
hash generation question
Stephan wrote: How's this related to the modules list? Anyhow, what about this: my $hashref = \%hash; $hashref = $hashref->{$_} foreach... -
S. Heiling #2
Re: Big hash question
"Tie your hash to a file, or use a database rather than a hash."
Well this is a rather odd experiment I'm tring.
And I'm trying to work it from a single script.
"Don't load the whole hash at startup."
How can I do that? Just simply being inside the script makes it load up
memory as far as I can tell. A long - long wait depending on size. I'd like
it to not load. I've tried to put it in a sub routine as well.
"If you want us to help you not load the whole hash at start-up,
you should show us the code that loads the hash, not the code that
later iterates over the hash."
I'm not loading it. It's just there.
And the script ends by running the hash.
This is what it looks like:
#####################################
%hash = (
key0 => "very long value.......",
key1 => "valy long value.......",
);
while ( ($key, $value) = each %hash) {
# The keys are file names or directory paths.
# The values are the file data unpacked into hex.."H"
}
#####################################
I've tried putting the hash after the while statement but still, a long
wait.
This is quite unconventional, I know, but is there a way?
Thanks.
S. Heiling Guest
-
Tad McClellan #3
Re: Big hash question
S. Heiling <newsreadermail@charter.net> wrote:
> And I'm trying to work it from a single script.
Perhaps you could just put the data in a __DATA__ section.
> "Don't load the whole hash at startup."
>
> How can I do that?
The post you quoted had code that does that.
I do not see that you even need a hash at all...
> %hash = (
>
> key0 => "very long value.......",
> key1 => "valy long value.......",
>
> );
Remove that code that loads the hash, put the data in __DATA__ instead.
> while ( ($key, $value) = each %hash) {
>
> # The keys are file names or directory paths.
> # The values are the file data unpacked into hex.."H"
>
> }> I've tried putting the hash after the while statement but still, a long
> wait.
Perl compiles your entire program, so where it is located in the
source code will not matter.
--------------------------------------> is there a way?
# untested
while ( <DATA> ) {
chomp;
my($key, $value) = split / => /;
# do stuff with only 1 pair at a time in memory
}
__DATA__
key0 => very long value.......
key1 => valy long value.......
--------------------------------------
See the "Scalar value constructors" section in perldata.pod
for info on the DATA filehandle and the __DATA__ token.
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
S. Heiling #4
Re: Big hash question
"Perhaps you could just put the data in a __DATA__ section."
Thanks. I'm working on using __DATA__, and it stops anything after that from
"compiling", but I'm having some trouble getting anything out of my hash.
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbh0ga9.anm.tadmc@magna.augustmail.com...> S. Heiling <newsreadermail@charter.net> wrote:
>>> > And I'm trying to work it from a single script.
>
> Perhaps you could just put the data in a __DATA__ section.
>
>>> > "Don't load the whole hash at startup."
> >
> > How can I do that?
>
> The post you quoted had code that does that.
>
> I do not see that you even need a hash at all...
>
>>> > %hash = (
> >
> > key0 => "very long value.......",
> > key1 => "valy long value.......",
> >
> > );
>
> Remove that code that loads the hash, put the data in __DATA__ instead.
>
>>> > while ( ($key, $value) = each %hash) {
> >
> > # The keys are file names or directory paths.
> > # The values are the file data unpacked into hex.."H"
> >
> > }
>>> > I've tried putting the hash after the while statement but still, a long
> > wait.
>
> Perl compiles your entire program, so where it is located in the
> source code will not matter.
>
>>> > is there a way?
> --------------------------------------
> # untested
> while ( <DATA> ) {
> chomp;
> my($key, $value) = split / => /;
>
> # do stuff with only 1 pair at a time in memory
> }
>
> __DATA__
> key0 => very long value.......
> key1 => valy long value.......
> --------------------------------------
>
>
> See the "Scalar value constructors" section in perldata.pod
> for info on the DATA filehandle and the __DATA__ token.
>
>
> --
> Tad McClellan SGML consulting
> [email]tadmc@augustmail.com[/email] Perl programming
> Fort Worth, Texas
S. Heiling Guest
-
Tad McClellan #5
Re: Big hash question
S. Heiling <newsreadermail@charter.net> wrote:
> "Perhaps you could just put the data in a __DATA__ section."
Who said that?
Please provide an attribution when you quote someone.
Please mark quoted text following Usenet convention, so you don't
confuse people's newsreaders.
Have you seen the Posting Guidelines that are posted here frequently?
> Thanks.
If you mean that, then please learn to compose followups properly.
Soon.
[ snip 75 lines of TOFU ]
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Ingo Fellner #6
Re: Big hash question
"S. Heiling" <newsreadermail@charter.net> wrote in message news:<vgu39at0610747@corp.supernews.com>...
foreach $key (keys %hash) {> I have a very large hash inside a script.
> The $values of the $keys can be very large.
>
> When the script runs, it takes a long time to load the hash.
> And this eats up memory...really fast!
> At least I'm assuming that's what it's doing.
>
> My question is, is there a way to stop this?
> How can I keep the whole hash from loading at startup?
>
> while ( ($key, $value) = each %hash) {
>
> # This is what I'm using for the hash
>
> }
>
$hash{$key} = "blabla";
# or:
print "$hash{$key}\n";
}
Rgds
Ingo ;-))
> Thanks.Ingo Fellner Guest



Reply With Quote

