The odd thing about anew is, it was created with anew. Sounds like a chicken & egg sort of deal, but the hint to solve this riddle is in the version number ;-)

#!/usr/local/bin/perl -w anew use warnings; use strict; use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; use Pod::Usage; # ======================================================== SETUP my $VERSION = v2.0.0; my %options; getopts('h', \%options); HELP_MESSAGE() if $options{'h'}; my $filename_chosen = $ARGV[0]; die "No target filename chosen. Try anew --help\n" unless $filename_chosen; my %templates = ( 'pm' => 'anew-mod.pm', 'pmo' => 'anew-obj.pm', 'pmf' => 'anewfunc.pm', 'pl' => 'anewmain.pl', 'c' => 'template.c', 'ly' => 'template.ly', 'htm' => 'template.htm', 'tex' => 'template.tex' ); # ========================================================= MAIN my ($extension_type) = ( $filename_chosen =~ m/\.([^\.]*)$/ ); my $extension; if ($extension_type) { die "Invalid extension. Try anew --help\n" unless $templates{$extension_type}; ($extension) = ( $templates{$extension_type} =~ m/\.([^\.]*)$/ ); } else { $extension = ''; $extension_type = 'pl'; } my $inputfile = $templates{$extension_type}; $filename_chosen =~ s/\.([^\.]*)$//; my $outputfile = $filename_chosen; $outputfile = "$outputfile.$extension" if $extension; print "Creating $outputfile from $inputfile . . . .\n"; die "** ERROR ** File exists ** This program never overwrites.\n" if (-f $outputfile); $inputfile = "/home/mccosar/share/anew/$inputfile"; open MODEL, "< $inputfile" or die "Couldn't open $inputfile : $!"; my @model = <MODEL>; close MODEL; open TARGET, "> $outputfile" or die "Can't open $outputfile : $!"; foreach (@model) { s/FILENAME/$outputfile/; print TARGET $_; } close TARGET; print "File created. Changing permissions . . . .\n"; my $perm = '600'; $perm = '700' if ($extension_type eq 'pl'); print `chmod -v $perm $outputfile` or die "Oops -- unable to chmod $perm $outputfile: $!"; print "Done.\n"; # ========================================================= SUBS sub HELP_MESSAGE { pod2usage ( { -exit_status => 0, -verbose_level => 1 } ); } sub VERSION_MESSAGE { return 1 if (lc $ARGV[0] eq "--help"); print "This program is $0, "; printf "version %vd\n", $VERSION; printf "(Using Perl v%vd)\n", $^V; exit 0; } __END__ =head1 NAME ~/bin/anew =head1 SYNOPSIS anew (filename.ext) Creates a new file from an appropriate template, based on ext: .pl or none : executable perl file .pm : perl module .pmf : perl module (.pm), functional .pmo : perl module (.pm), objective .c : c source code .ly : GNU Lilypond leadsheet .htm : Elementary html document .tex : Basic .tex document With no extension specified, anew assumes you want an executable perl file. =head1 OPTIONS =over 4 =item -h, --help Prints synopsis and options, then exits. =item --version Prints version information and exits. =back =head1 AUTHOR Bruce H. McCosar. =head1 COPYRIGHT Copyright 2004 by Bruce H. McCosar. All Rights Reserved. This program is free software. You may copy or distribute it under the same terms as Perl itself.

And, of course, once you post code in public, you become acutely aware of the hacks . . . . but the important thing is, I wrote it and it works.

$jPxu=q?@jPxu?;$jPxu^=q?Whats?^q?UpDoc?;print$jPxu;

In reply to Re^3: Need Perl book advice by Ambidangerous
in thread Need Perl book advice by phobia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.