citromatik has asked for the wisdom of the Perl Monks concerning the following question:
Hi all
I am storing some data in a long string of "ints":
open my $fh, "<", $file or die $!; while (<$fh>){ my ($key,$val) = split /\t/; substr($bin,$key*4,4,pack("N",$val)); }
Since the $keys in the file are not sorted, I need to initialize substr with enough values (to avoid a "substr outside of string" error). Currently I am doing it like follows:
substr($bin,$_*4,4,pack ("N",0)) for (0..$last_val);
Is there a more efficient way (maybe in one go instead of looping) of doing this?
Thanks in advance
citromatik
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Fast string construction
by johngg (Canon) on Apr 07, 2011 at 13:59 UTC | |
Re: Fast string construction
by Eliya (Vicar) on Apr 07, 2011 at 13:15 UTC | |
Re: Fast string construction
by ikegami (Patriarch) on Apr 07, 2011 at 16:06 UTC | |
by sundialsvc4 (Abbot) on Apr 07, 2011 at 17:41 UTC |
Back to
Seekers of Perl Wisdom