view build-aux/inplace_edit.pl @ 31189:820d2c802247 stable

fortran_vec: Fix instances of method chaining that may cause dangling pointer. * libinterp/corefcn/quandcc.cc (Fquadcc): Replace method chaining with a separate line for NDArray object to avoid going out of scope. * libinterp/corefcn/__ilu__.cc (F__iluc__): Obtain RowVector and ColumnVector objects in separate line to remain in scope. * libinterp/corefcn/__ichol__.cc (F__icholt__): Obtain RowVector object in separate line to remain in scope. For more details: https://octave.discourse.group/t/3132
author Maged Rifaat <magedrifaat@gmail.com>
date Mon, 15 Aug 2022 00:22:55 +0200
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.$$:$!";
}