Skip to content

Instantly share code, notes, and snippets.

@rjbs
Created October 8, 2022 15:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjbs/8667018cd7dacdce768a8c32f551778c to your computer and use it in GitHub Desktop.
Save rjbs/8667018cd7dacdce768a8c32f551778c to your computer and use it in GitHub Desktop.
#!/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