Skip to content

Instantly share code, notes, and snippets.

@mishin
Last active August 29, 2015 14:22
Show Gist options
  • Save mishin/da259951b43f6bb37b83 to your computer and use it in GitHub Desktop.
Save mishin/da259951b43f6bb37b83 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use 5.010;
use Path::Iterator::Rule;
use File::Slurp;
die "Usage: $0 DIRs" if not @ARGV;
my $rule = Path::Iterator::Rule->new;
$rule->name("*.pm");
my $it = $rule->iter(@ARGV);
while ( my $file = $it->() ) {
say "use strict added to $file";
add_strict_to_file($file);
}
sub add_strict_to_file {
#http://perlmaven.com/splice-to-slice-and-dice-arrays-in-perl
my ($file) = @_;
my @lines = read_file($file);
my @strict = ( 'use strict;', 'use warnings;', '' );
splice @lines, 1, 0, ( join "\n", @strict );
write_file( $file, \@lines );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment