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

[MacPerl] <> Inplace editing question



I'm trying to adapt one of Chris Nandor's examples from the MacPerl CD.  I
want a droplet to take a directory and process all the files in the
directory to convert Unix line endings to Mac line endings.  The example on
the CD works with dropped files, but not directories.

For some reason, with the code below, if I drop a files it works fine.  If
I drop a directory, it doesn't work.  I added the line in the lf2cr
subroutine print "@_\n"; to test what's being passed into the subroutine.
I'm testing with a directory that contains one file.  If I drop the file,
the output is:
Data:WWW:kvh-bin:Text:Ini.pm
and everything works.

If I drop a directory, the output is:
Data:WWW:kvh-bin:Text:Ini.pm
# Can't open Data:WWW:kvh-bin:Text: No such file or directory

It appears to me that the print statement is producing the exactly the same
thing, so what the heck did I do wrong?

I'm using MacPerl 5.1.9r4 with 8MB memory partition.

Thanks for any help.

Here's the script that fails:
#!perl -w
# script to take file(s)/folder(s) and convert to mac text files

sub lf2cr;

for ($i = 0; $i <= $#ARGV; $i++) {
	$filename = $ARGV[$i];
	if (-d $filename) {
		opendir DIR, $filename or die "can't opendir $filename: $!";
		@dirs = readdir DIR;
		closedir DIR;
		# readdir returns names of files, but not paths.  add the path
		for ($j = 0; $j <= $#dirs; $j++) {
			$dirs[$j] = $filename.':'.$dirs[$j];
			lf2cr ($dirs[$j]);
		}
	} elsif (-f $filename) {
		lf2cr ($filename);
	}
}

sub lf2cr {

	print "@_\n";

	# lf2cr4mac.pl - droplet to convert <CR.<LF> and/or <LF> to <CR>.
	#
	# Written by Chris Nandor, 9712.

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

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




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch