我正在Perl打一个 has。 我在座标时遇到了记忆错误:
foreach $key (sort (keys(%hash))) {
....
}
我如何打上有吨数据的洗衣?
我正在Perl打一个 has。 我在座标时遇到了记忆错误:
foreach $key (sort (keys(%hash))) {
....
}
我如何打上有吨数据的洗衣?
<代码>>(hash>>在大型<代码>%hash上,密码>低效,其中,记忆明智,大致相当于:
my @keys = keys %hash;
@keys = sort @keys;
在进行分类时,它必须保存三本钥匙的复印件(其中一份在散列,一份在钥匙清单中,一份在分类清单中)。 <代码>foreach 存储器优化不适用。
由于洗衣如此庞大,最好的选择是完全摆脱记忆。 在BerDB的档案中标出。 如果你想要把钥匙保留下来,以便 has子不成为最佳选择,那么树就是树。 我建议使用Berker BTree档案。 树木将有效地保持像一个阵列这样的数据,同时提供像一个 has一样的快速勘测。
这里的例子有:BerkeleyDB.DB_File 较为简单,但并未利用伯克斯银行的现代特征。 YMMV。
use BerkeleyDB;
my $db = tie my %hash, BerkeleyDB::Btree ,
-Filename => "your.db",
-Compare => sub { $_[1] cmp $_[0] },
-Flags => DB_CREATE;
<代码>-Compare说明了如何提供自己的分类功能。 捆绑的接口将简练。 除非你需要,否则,它就使用物体界面。
Perl FAQ有一些实例可以分类。 查阅,这里是:
如果贵方的钥匙是小幅最大大小的分类、编号或扼杀,你可以使用:
use Sort::Packed qw(sort_packed);
my $hash_size = keys %hash;
my $max_key_len = 4;
my $packed_keys = x ($max_key_len * $hash_size);
my $ix = 0;
while (my ($key, $value) = each %hash) {
my $key_len = length $k;
$key_len <= $max_key_len or die "key $key is too big";
substr($packed_keys, $ix, $key_len, $key);
$ix += $max_key_len;
}
sort_packed("C$max_key_len", $packed_keys);
$ix = 0;
while ($ix < length $packed_keys) {
my $key = substr($packed_keys, $ix, $max_key_len);
$key =~ s/ +$//;
print "$key
";
$ix += $max_key_len;
}
诚然,这部法典是相当令人怀疑的,但它将尽量减少记忆的使用。
I am building a Web interface to monitor an embedded system. I have built a Perl script which runs remote commands and gathers output from that system. Now what I need is a Web interface which makes ...
How do I tell what type of value is in a Perl variable? $x might be a scalar, a ref to an array or a ref to a hash (or maybe other things).
When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...
I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...
I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...
I would like to submit a form to a CGI script localy (w3c-markup-validator), but it is too slow using curl and apache, I want to use this CGI script more than 5,000 times in an another script. and ...
So I m running perl 5.10 on a core 2 duo macbook pro compiled with threading support: usethreads=define, useithreads=define. I ve got a simple script to read 4 gzipped files containing aroud 750000 ...
A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...