I wrote this script because I just wanted to automate typing two lines of Perl every time I wrote a small test-case script.
This is dead simple and doesn't really count as 'cool'. However, in the words of the Greek poet Callimachus and E.F. Shumacher, "small is beautiful".
The script simply prints its own top two lines into every new file specified on the command line, unless the file already exists.
Any and all feedback will be welcomed.
#!/usr/bin/env perl use Modern::Perl; while (<@ARGV>) { my $fname = $_; unless (-e $fname) { open my $fh, '>', $fname; say $fh "#!/usr/bin/env perl"; say $fh "use Modern::Perl;\n\n"; say STDOUT "created $fname"; } else { say STDOUT "*** didn't overwrite $fname"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: simple Perl script template
by jeffa (Bishop) on Apr 09, 2015 at 15:04 UTC | |
by Dumu (Monk) on Apr 09, 2015 at 15:53 UTC | |
Re: simple Perl script template
by roboticus (Chancellor) on Apr 09, 2015 at 11:11 UTC | |
by afoken (Chancellor) on Apr 09, 2015 at 11:33 UTC | |
by hdb (Monsignor) on Apr 09, 2015 at 12:13 UTC | |
by Dumu (Monk) on Apr 09, 2015 at 12:47 UTC | |
by Dumu (Monk) on Apr 09, 2015 at 12:34 UTC | |
Re: simple Perl script template
by pme (Monsignor) on Apr 09, 2015 at 11:40 UTC | |
by Dumu (Monk) on Apr 09, 2015 at 12:55 UTC | |
by marinersk (Priest) on Apr 09, 2015 at 12:14 UTC | |
by Dumu (Monk) on Apr 09, 2015 at 12:49 UTC | |
by pme (Monsignor) on Apr 09, 2015 at 13:35 UTC | |
by marinersk (Priest) on Apr 09, 2015 at 16:11 UTC |