Owen wrote:
On Mon, 12 Apr 2010 13:52:16 +0200
Rene Schickbauer <rene.schickba...@gmail.com> wrote:

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;

All files on a binary computer are composed of 1s and 0s.  :-)


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";

Why are you copying $rng to a string?

perldoc -q quoting


while (<$RNG>) {
    my @bits    = split //;
    my $nr_bits = @bits;

If you want a bit count then that should be:

     my $nr_bits = 8 * @bits;

Although you don't need to create an array to count bytes:

     my $nr_bytes = tr///c;


    print "Number of bits in the file is $nr_bits\n";
}

If you want the size of a file just use the -s operator:

print "Number of bytes in the file is ", -s $rng, "\n";


===============================================================
o...@owen-desktop:~/P/Perlscripts$ perl beg1.pl
Number of bits in the file is 15689303

So there are no newlines in your file?


Not the best way to get the file size :-)



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to