zytu has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, How to open a file more than 2.6 GB? When I tried to use open() to open a file more than 2.6 GB it failed. I need someone's help. Thank you all very much!

Replies are listed 'Best First'.
Re: How to open a file more than 2.6 GB?
by sgifford (Prior) on Nov 29, 2005 at 03:09 UTC
    In a pinch, a good trick can be to use cat largefile.txt |perl yourscript.pl. That's what I used to do on Solaris with an old Perl. A version of Perl without >2GB file support can read from a pipe just fine, even if that pipe happens to contain a file larger than 2GB.

    The real solution, as everybody else has said, is get a copy of Perl with large files support, either by getting it in a package or by recompiling it.

Re: How to open a file more than 2.6 GB?
by BrowserUk (Patriarch) on Nov 29, 2005 at 01:09 UTC

    What output do you get from typing perl -V:uselargefiles?

    If you don't get:

    uselargefiles='define';

    then you will either need to rebuild your copy of it with that option enabled in the makefile, or obtain a copy of perl so built.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Unfortunately, the output is: uselargefiles='UNKNOWN'; So, if I want to use this option, how to add it into makefile? I didn't find it in the makefile. Can I add it into the makefile directly? Or can I do this in the process of configuration? Thank you very much!

        It depends upon which platform you are running on.

        On win32, you would need to edit the makefile (in the win32 subdirectory) and uncomment the line

        #USE_LARGE_FILES = define

        If you are running on other platforms, you can probably do this as a part of the configure step, but you'll need to look at the readme.XXX where XXX is your platform for the details.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to open a file more than 2.6 GB?
by jonadab (Parson) on Nov 29, 2005 at 00:53 UTC

    In general, this either will Just Work, or else it won't work.

    Whether it works or not depends. It depends on stuff. It potentially can depend, for instance, on what operating system you're using, what filesystem (e.g., on Windows it can matter whether it's FAT32 or NTFS, and of course it's never possible with FAT16), what hardware architecture (in particular, whether it's a 32-bit or 64-bit architecture), what compiler was used to compile your perl, what version of which set of C standard libraries it was compiled against and how they were configured when they were compiled, which compiler options were used, and assorted other arcane circumstances you may or may not have any control over.

    I'm assuming here that the only problem is that the file is over 2GB. You *did* try your same code, with no changes at all, with a smaller-than-2GB file first, I assume, to make absolutely sure that the file size is the only problem. If not, do so forthwith. Otherwise, my next advice would be to try it on a different computer with a different perl and, if possible, a different operating system and filesystem. As a rule of thumb, it is somewhat more likely to work on more recent versions of perl, on more recent operating systems, and especially on 64-bit systems.

      The platform information is: Machine hardware: sun4u OS version: 5.8 Processor type: sparc Hardware: SUNW,Ultra-5_10 The perl we use is 5.005_03. I will do some test later. Thank you!
        You might want to upgrade your Perl. From the current INSTALL file:
        =head3 Large file support. Since Perl 5.6.0, Perl has supported large files (files larger than 2 gigabytes), and in many common platforms like Linux or Solaris this support is on by default. This is both good and bad. It is good in that you can use large files, seek(), stat(), and -s them. It is bad in that if you are interfacing + Perl using some extension, the components you are connecting to must also be large file aware: if Perl thinks files can be large but the other parts of the software puzzle do not understand the concept, bad things will happen. One popular extension suffering from this ailment is the Apache extension mod_perl. There's also one known limitation with the current large files implementation: unless you also have 64-bit integers (see the next section), you cannot use the printf/sprintf non-decimal integer format +s like C<%x> to print filesizes. You can use C<%d>, though.
        This doesn't mean you can't get large file support on older versions of Perl, but you might have to recompile perl for that. Read the INSTALL file, and in your case, README.solaris might need a read as well.

        But you're much better of to upgrade. 5.005_03 dates from March 1999. Get at least 5.6.2, preferably 5.8.7. And you now have a reason to upgrade ;-)

        Perl --((8:>*