[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [MacPerl] Changing a file (pseudo) in-place?



This is addressed on page 332 of the new Camel book. If you provide
the "-i" switch with no extension, then you do not get a backup file and
do not have to do the unlink of the backup file. Since 'undef-ing' $^I is
supposed to turn off inplace editing, I suspect that  $^I = "";  would be
the equivalent of "-i", and thus the script might reduce to simply:

	$/ = "\012";
	$^I = "";
	while ( <> ) { s/\012/\015/g; print; }

----------
From: 	Chris Nandor
Sent: 	Wednesday, February 05, 1997 8:37 PM
To: 	Michael Schuerig
Cc: 	mac-perl@iis.ee.ethz.ch
Subject: 	Re: [MacPerl] Changing a file (pseudo) in-place?

At 17:40 2/5/97, Michael Schuerig wrote:
>This is probably obvious, alas, I don't know how to do it.
>I want to change a file. Actually I want to process it's contents, write
>the result to a temp file, exchange the contents of original and temp file,
>and then delete the temp file.
>
>Michael

#       This script fixes problem caused by UNIX text files impported to the
#       Mac in binary mode, so lines are terminated with LF instead of CR.
#       Drop your files on the following droplet:
#!/usr/local/bin/perl5

$/ = "\012";
$^I = ".orig";

@temp = @ARGV;

while (<>) {
    s/\012/\015/g;
    print;
}

foreach (@temp) {
    unlink $_.".orig";
}