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

[MacPerl] Parenthesis problem



Ok, I wrote a simple CHANGE program which does multiple
file changes.  When I run it though, I get this:

Files to change>*.c
Ignore case in the files? n
String to look for>(getByte
String to insert>(MLF_getByte

And I get back:

Reading /tmp_mnt/disk4/mark/gr/fileio.c...please wait.
/(getByte/: unmatched () in regexp at /disk4/mark/bin/chg line 80.

When I try putting in:

Files to change>*.c
Ignore case in the files? n
String to look for>\(getByte
String to insert>\(MLF_getByte

I get:

Reading /tmp_mnt/disk4/mark/gr/fileio.c...please wait.
new:            theWordL =  (USHORT) \(MLF_getByte() & 0xff);
new:            theWordL = ((USHORT) \(MLF_getByte() & 0xff)) | (theWordL << 0x08);
new:                    theWordL  =   (USHORT) \(MLF_getByte() & 0xff);
new:                    theWordL |= (((USHORT) \(MLF_getByte() & 0xff)) << 0x08);
new:            theLongL =  (ULONG) \(MLF_getByte() & 0xff);
new:            theLongL = ((ULONG) \(MLF_getByte() & 0xff)) | (theLongL << 0x08);
new:            theLongL = ((ULONG) \(MLF_getByte() & 0xff)) | (theLongL << 0x08);
new:            theLongL = ((ULONG) \(MLF_getByte() & 0xff)) | (theLongL << 0x08);
new:                    theLongL  =   (ULONG) \(MLF_getByte() & 0xff);
new:                    theLongL |= (((ULONG) \(MLF_getByte() & 0xff)) << 0x08);
new:                    theLongL |= (((ULONG) \(MLF_getByte() & 0xff)) << 0x10);
new:                    theLongL |= (((ULONG) \(MLF_getByte() & 0xff)) << 0x18);
Writing fileio.c....  Made 0 changes.
Reading /tmp_mnt/disk4/mark/gr/gif.c...please wait.
Writing gif.c....  Made 0 changes.
Reading /tmp_mnt/disk4/mark/gr/gr.c...please wait.
Writing gr.c....  Made 0 changes.
Reading /tmp_mnt/disk4/mark/gr/mmf.c...please wait.
Writing mmf.c....  Made 0 changes.
Reading /tmp_mnt/disk4/mark/gr/sgi.c...please wait.
Writing sgi.c....  Made 0 changes.

As you can see - it puts in the backslash before the
parenthesis.  Various combinations of these two result in
either just the error or the same as the above.

Total number of changes made to the files: 0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Ok, now I'm writing this on a Unix system, but I'm
transferring it to my Mac at home also (and the one here at
work).  I get the same kind of message on both Macs.  The
Mac at home is running the current release of MacPerl and
the one here at work is running the previous version.  The
Unix version is 5.004.

Ideas on a work-around?  Thanks! :-)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Here's the program:

#!perl

	require 'getopt.pl';

	srand;
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	$mon += 1;
	$curDate = sprintf( "%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $mon, $mday, $year, $hour, $min, $sec );
	$theDirectory = `pwd`;
	chomp( $theDirectory );

	&Getopt( 'f:hin:o:' );

	if( $opt_h ){
		print <<HELP_END;
Change (chg)
Version 1.0a

Change modifies the contents of a file.  The options are:

F	The filename(s)
H	This text
I	Whether or not to ignore case
O	The string to look for (input)
N	The string to substitute (output)

Example:

	chg -f*.c -i -o"Look for this" -n"Make it this"
HELP_END

	exit( 0 );
	}

	system( "clear" );
	if( $opt_f == NULL ){
		print "Files to change>";
		$opt_f = <STDIN>;
		chop( $opt_f );

		print "Ignore case in the files? ";
		$opt_i = <STDIN>;
		chop( $opt_i );
		}

	if( $opt_o == NULL ){
		print "String to look for>";
		$opt_o = <STDIN>;
		chop( $opt_o );
		}

	if( $opt_n == NULL ){
		print "String to insert>";
		$opt_n = <STDIN>;
		chop( $opt_n );
		}

	open( THEFILE, "ls -1 $opt_f|" ) || die "Couldn't read the file list\n";
	@theFiles = <THEFILE>;
	close( THEFILE );

	for( $i=0; $i<=$#theFiles; $i++ ){
		chomp( $theFiles[$i] );
		}

	$totChanges = 0;
	for( @theFiles ){
		print "Reading $theDirectory/$_...please wait.\n";
		open( THEFILE, "$theDirectory/$_" ) || die "Couldn't open $_ to read\n";
		@theListing = <THEFILE>;
		close( THEFILE );

		$theCount = 0;
		for( $i=0; $i<=$#theListing; $i++ ){
			if( $theListing[$i] =~ /$opt_o/i ){
				$theCount++;
				system( "clear" );
				print "old: $theListing[$i]";
				}

			if( $opt_i =~ /y/i ){
				$theListing[$i] =~ s/$opt_o/$opt_n/ig;
				}
				else {
					$theListing[$i] =~ s/$opt_o/$opt_n/g;
					}
			if( $theListing[$i] =~ /$opt_n/i ){
				print "new: $theListing[$i]";
				}
			}

		$totChanges += $theCount;
		print "Writing $_....  Made $theCount changes.\n";
		open( THEFILE, ">$theDirectory/$_" ) || die "Couldn't open $_ to write\n";
		print THEFILE @theListing;
		close( THEFILE );
		}

	print "\n\nTotal number of changes made to the files: $totChanges\n";
	exit( 0 );

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