Re: [MacPerl-AnyPerl] Speed of reformatting large file

[email protected] (Chris Nandor) Tue, 31 Jul 2001 17:49:26 -0400
Newsgroups perl.macperl.anyperl
Message-ID <p05100301b78cd71985d1@[10.0.1.177]>
At 16:46 -0400 2001.07.31, Adam Witney wrote:
>I have a file which contains about 45000 lines of 50 characters each. I want
>to reformat it to contain 60 characters each.
>
>I can read the whole file in and remove the line endings and then print out
>lines of 60 characters, but this can take some time. And I may need to do
>this on bigger files still.
>
>Is there a quicker way?

I would look into the -p switch.  Given your input file in $ARGV[0]:

#!/usr/bin/perl -pi.orig
chomp;
$_ .= "0123456789\n";
__END__

It will loop over the file, reading each line and writing out to a file of
the same name (but backing up the original to file.orig).

-- 
Chris Nandor                      [email protected]    http://pudge.net/
Open Source Development Network    [email protected]     http://osdn.com/