[Matrix-SIG] We should rename convolve in multiarraymodule

Les Schaffer godzilla@netmeg.net (Les Schaffer)
Wed, 31 Mar 1999 11:29:08 -0500 (EST)


Scott Ransom writes:

> I agree.  And here is the Perl script:
> perl -p -i -e 's/convolve\(/correlate\(/o' *.py

i'd make that 

perl -p -i.orig -e 's/convolve/correlate/g' *.py

so that you get backups of any files that are changed...

or, i'll see your one-liner and raise you 28.

usage (*nix):

subst convolve correlate `find . -name "*.py"`

subst will keep original copies of any file its changed, and also
provide a listing of exactly what changes it did make (diff -c) to
stdout.  if it makes changes to file.py, it copies the permissions of
the original to the updated version.

the first and second arguments also take some subset of perl regexps
if you have something more tricky.

les schaffer

=============== subst ====================

#!/usr/bin/perl

my $PATTERN = $ARGV[0]; 
my $SUBPAT  = $ARGV[1]; 
shift;
shift; 

foreach $file ( @ARGV) {

  $NEWFILE = $file.".tmp"; 
  $OLDFILE = $file.".orig"; 
  
  open(FILE, $file);
  open(OUT, ">$NEWFILE");

  @stats = stat $file;
  $mode = $stats[2];

  while  (<FILE> ) {
    $_ =~ s/\Q$PATTERN/\Q$SUBPAT/g; 
    printf OUT "%s", $_; 
  }

  close(FILE);
  close(OUT); 

  @diff = `diff -c $file $NEWFILE `;
  printf ("%s", "@diff");
  
  if ( $#diff < 0 ) {
      printf "No changes in %s ...\n", $file;
      unlink $NEWFILE;
  } else {
      rename $file, $OLDFILE ;
      rename $NEWFILE, $file; 
      chmod $mode, $file;
  }


}