Mercurial > octave
annotate build-aux/inplace_edit.pl @ 31207:1c40fc2344f4 stable
quad2d.m: Add BIST test to cset b0e90ca8e679 (bug #62972)
* quad2d.m: Add BIST test for bug #62972.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 28 Aug 2022 14:19:43 -0700 |
parents | 8b548f2f8086 |
children |
rev | line source |
---|---|
25533
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
1 #!/usr/bin/perl -w |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
2 |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
3 ################################################################################ |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
4 ## File: inplace_edit.pl |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
5 ## Usage: perl inplace_edit.pl 'PERL_CODE' file1 [file2] [...] |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
6 ## Purpose: Run snippet of PERL_CODE on each line in a file and replace |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
7 ## existing line with the results of running the code. |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
8 ## This replaces perl -i -pe 'PERL_CODE' file1 [file2] ... |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
9 ## due to a problem in Perl 5.28 which restricts the number of files |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
10 ################################################################################ |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
11 |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
12 ## Create Perl code from first argument (-e CODE) |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
13 eval "sub per_line_code { $ARGV[0]; }"; |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
14 shift @ARGV; |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
15 |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
16 ## Loop over each file |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
17 foreach $fname (@ARGV) |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
18 { |
25828
8b548f2f8086
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25533
diff
changeset
|
19 rename ($fname, "$fname.$$") or die "Rename failed:$fname:$!"; |
8b548f2f8086
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25533
diff
changeset
|
20 open (my $FHI, "<", "$fname.$$") or die "Open failed:$fname.$$:$!"; |
8b548f2f8086
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25533
diff
changeset
|
21 open (my $FHO, ">", "$fname") or die "Open failed:$fname:$!"; |
25533
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
22 |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
23 ## Loop over each line |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
24 while (<$FHI>) |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
25 { |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
26 per_line_code (); |
25828
8b548f2f8086
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25533
diff
changeset
|
27 print $FHO $_; |
25533
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
28 } |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
29 |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
30 close ($FHI); |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
31 close ($FHO); |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
32 unlink "$fname.$$" or die "Delete failed:$fname.$$:$!"; |
d6850dd2a6b4
build: Work around bug in perl 5.28.0 (bug #54202).
Rik <rik@octave.org>
parents:
diff
changeset
|
33 } |