An Odd Little Script

Nick Craig-Wood nick at craig-wood.com
Thu Mar 10 05:30:02 EST 2005


Terry Hancock <hancock at anansispaceworks.com> wrote:
>  The only problem I see is the "in place" requirement, which seems silly
>  unless by "quite large" you mean multiple gigabytes.  Surely Perl
>  actually makes a copy in the process even though you never see
>  it?

If using "perl -i" then then it does make a copy

       -i[extension]
            specifies that files processed by the "<>" construct are to be
            edited in-place.  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.

The solution posted previously using mmap actually does it in-place
though which will work very well for files < 4GB. (And not at all for
files > 4GB unless you are on a 64 bit machine).

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list