view build-aux/inplace_edit.pl @ 33232:c5dc54712378

update help function tests * test/help/cdefdir/cdef_help3.m, test/help/cdefdir/cdef_help4.m, test/help/undoc_fcn.m: New files. * test/help/cdefdir/cdef_help1.m: Rename from test/bug-65220/cdefdir/cdef_help1.m. * test/help/cdefdir/cdef_help2.m: Rename from test/bug-65220/cdefdir/cdef_help2.m. * test/help/help.tst: Rename from test/bug-65220/bug-65220.tst. New tests. Split tests so there is one assert for each test so that it is easier to find an individual failing test. * test/help/module.mk: Rename from test/bug-65220/module.mk. Update. * test/Makefile.am: Update.
author John W. Eaton <jwe@octave.org>
date Thu, 21 Mar 2024 11:21:04 -0400
parents 8b548f2f8086
children
line wrap: on
line source

#!/usr/bin/perl -w

################################################################################
## File: inplace_edit.pl
## Usage: perl inplace_edit.pl 'PERL_CODE' file1 [file2] [...]
## Purpose: Run snippet of PERL_CODE on each line in a file and replace
## existing line with the results of running the code.
## This replaces perl -i -pe 'PERL_CODE' file1 [file2] ...
## due to a problem in Perl 5.28 which restricts the number of files
################################################################################

## Create Perl code from first argument (-e CODE)
eval "sub per_line_code { $ARGV[0]; }";
shift @ARGV;

## Loop over each file
foreach $fname (@ARGV)
{
  rename ($fname, "$fname.$$") or die "Rename failed:$fname:$!";
  open (my $FHI, "<", "$fname.$$") or die "Open failed:$fname.$$:$!";
  open (my $FHO, ">", "$fname") or die "Open failed:$fname:$!";

  ## Loop over each line
  while (<$FHI>)
  {
    per_line_code ();
    print $FHO $_;
  }

  close ($FHI);
  close ($FHO);
  unlink "$fname.$$" or die "Delete failed:$fname.$$:$!";
}