On Mon, 12 Apr 2010 13:52:16 +0200
Rene Schickbauer <[email protected]> wrote:
> Hi!
>
> > Perl has no string length limit. You are only limited by the amount
> > of memory that is available.
> >
> > If your program is misbehaving then I fear it is the programs error
> > (or well the person that wrote it ;-) rather then perl or any limit
> > on the length of a string.
>
> And as for the current implementation, i think it's 2 or 4 GB
> (uint/sint index into string length?).
>
> But basically, if you have a single scalar of that size, the perl
> interpreters limits should be the least of your problems. If you're
> going this way, please redesign (a single, accidental copy of a
> string has the potential to bring the system to a standstill).
>
> But a few megabytes won't be any problem...
> ...until you do something unwise like split// and turn you scalar
> into a multi-million elements array.
I have a file of 1s and 0's that is 15689303 bytes;
running the program below takes about 10 seconds on reasonably fast dual
core with 4 GByte of RAM
===============================================================
#!/usr/bin/perl
use strict;
use warnings;
my $rng = "/home/owen/rng_formatted";
open (my $RNG, "<", "$rng") or die "$!\n";
while (<$RNG>) {
my @bits = split //;
my $nr_bits = @bits;
print "Number of bits in the file is $nr_bits\n";
}
===============================================================
o...@owen-desktop:~/P/Perlscripts$ perl beg1.pl
Number of bits in the file is 15689303
Not the best way to get the file size :-)
Owen
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/