Created
October 8, 2022 15:20
-
-
Save rjbs/8667018cd7dacdce768a8c32f551778c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env perl | |
use v5.36.0; | |
my $fn = $ARGV[0]; | |
my @output; | |
{ | |
open my $fh, '<', $fn; | |
my @input = <$fh>; | |
LINE: while (my $line = shift @input) { | |
if ($line =~ /^sub (\S+) \{$/) { | |
my $sub = $1; | |
my $next = shift @input; | |
if ($next && $next =~ /^\s*my (\([^)]+\)) = \@_;$/) { | |
my $sig = $1; | |
my $new_line = "sub $sub $sig {\n"; | |
warn $new_line; | |
push @output, $new_line; | |
while (@input && $input[0] !~ /\S/) { | |
shift @input; | |
} | |
next LINE; | |
} | |
unshift @input, $next; | |
} | |
push @output, $line; | |
} | |
} | |
open my $fh, '>', $fn; | |
print {$fh} @output; | |
close $fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment