view build-aux/inplace_edit.pl @ 30242:33d895260fa4

publish.m: Support some non-ASCII characters in comments for pdf output. * scripts/miscellaneous/publish.m: Clarify documentation. Publishing Markup is only interpreted in section comments. Remove sentence that suggests that commands in the output format might be interpreted in that format. * scripts/miscellaneous/private/__publish_latex_output__.m: Add substitution rules for some multi-byte UTF-8 characters (mostly Latin-based) to LaTeX publish template. This fixes a bug where using these characters in comments would cause `pdflatex` to fail. See: https://github.com/gnu-octave/octave/pull/5
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 17 Oct 2021 12:28:51 +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.$$:$!";
}