Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Muy Large File

by TilRMan (Friar)
on Mar 14, 2005 at 10:33 UTC ( [id://439218] : note . print w/replies, xml ) Need Help??

in reply to Muy Large File

Update: As thor points out, my solution here is quite wrong. Sorry.

On unixy platforms, Perl has exactly what you need already built in. (Windows users may need a binmode somewhere.)

#!/usr/bin/perl -w -pi use strict; tr/A-Z/ /;

If your records do not have newlines at the end, then you will need to set the record length. Add the following line to the script, replacing 4096 with the record length:

BEGIN { $/ = \4096 }

The magic is in the -pi which turns on in-place editing in a loop (more at perlrun). Then the tr/// operator runs on every record, replacing the offending characters with spaces (more at perlop). Use tr/// instead of s///; it's probably faster and safer.

Note: Code is mostly untested. Use with caution.

Replies are listed 'Best First'.
Re^2: Muy Large File
by thor (Priest) on Mar 14, 2005 at 13:28 UTC
    The problem is that while the -i switch is the "in place" switch, it isn't really in place. From perldoc perlrun
    It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements.
    As per the OP, the file is too large to do this with.


    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come