John Bokma
Vlad Tepes
John Bokma
Vlad Tepes
You could perhaps use the fact that hashes have unique keys.
Try building a hash with the values from the array:
map $hash{$_} = 1, @a; # this will be more efficient [...]
how about
my %hash;
@hash{@a} = ( "" ) x @a;
Why store anything at all?
@hash{@a} = ( undef ) x @a;
And what is undef? Is it not stored?
I always thought that an empty string was something, while undef was
nada. I may be wrong. But... with a testfile
my @a = 0..1e5;
my %hash;
## @hash{@a} = ( "" ) x @a;
@hash{@a} = ( undef ) x @a;
$hash{234} = <STDIN>;
I got the following sizes when looking at output from ips(1):
empty strings: 26212 kB
undef values: 20700 kB
Some quick calculations give:
26212 - 20700 = 5512
5512 * 1024 / 1e5 = 56.44288
So setting a hash value to undef at least appears to save about
56 bytes memory compared to storing it as an empty string.
Wether undef actually is anything, I don't know.
If it isn't, then it can't be stored either ... or what?