V
Vishal G
Hi Guys,
Very basic question....
Please dont suggest to use other programing language or other data
structure cause I can't...
I read data from file and yes I have to slurp the whole thing to
memory cause I can use upto 4GB...
data in file is in this format
30 56 78 34 2 39 87 (50 values per line, total of 120 million
entries)
reading file in paragraph mode
Now I have to remove multiple spaces without using much memory
This is what I have wrote (might be very low standard code for Gurus
out there)
It works but takes 5 mins consuming 600-700 MB, if I use substitution
to achieve this it takes 4-5 GB and around 2-3 mins...
Could you pls suggest way to process it faster using less memory
possible...
# Process the string $_ to remove leading whitespaces,
multiple whitespaces
# and to padd each value to same size
my $chr = '';
my $str = '';
my $value = '';
my $unitlength = $Alignment::BASEQUALITY_BYTES;
while (length($_) > 0) {
if (($chr = substr($_, 0, 1, "")) ne " ") {
$value = $value . $chr;
} else {
$str = $str . sprintf("%${unitlength}d",
$value) if ($value);
undef $value;
}
}
# BQ field
$ace->{'BQ'}->{$name} = $str;
undef $str;
undef $chr;
Thanks in advance
Vishal
Very basic question....
Please dont suggest to use other programing language or other data
structure cause I can't...
I read data from file and yes I have to slurp the whole thing to
memory cause I can use upto 4GB...
data in file is in this format
30 56 78 34 2 39 87 (50 values per line, total of 120 million
entries)
reading file in paragraph mode
Now I have to remove multiple spaces without using much memory
This is what I have wrote (might be very low standard code for Gurus
out there)
It works but takes 5 mins consuming 600-700 MB, if I use substitution
to achieve this it takes 4-5 GB and around 2-3 mins...
Could you pls suggest way to process it faster using less memory
possible...
# Process the string $_ to remove leading whitespaces,
multiple whitespaces
# and to padd each value to same size
my $chr = '';
my $str = '';
my $value = '';
my $unitlength = $Alignment::BASEQUALITY_BYTES;
while (length($_) > 0) {
if (($chr = substr($_, 0, 1, "")) ne " ") {
$value = $value . $chr;
} else {
$str = $str . sprintf("%${unitlength}d",
$value) if ($value);
undef $value;
}
}
# BQ field
$ace->{'BQ'}->{$name} = $str;
undef $str;
undef $chr;
Thanks in advance
Vishal