chakreey has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I came across the following few lines at the beginning of a python script. I write short programs in perl and would like to share my scripts with others. It will be very useful it this kind of meta-information is created/modified automatically whenever I write/edit a script. (I use gedit to write scripts on ubuntu OS)

If you know of any perl script or software/addon or any other pointers to do this, kindly share.

#!/usr/bin/env python # join_proteins.py --- # # Filename: join_proteins.py # Description: # Author: Andy Bork # Maintainer: # Copyright (C) 2010 Andy Bork, all rights reserved. # Created: Sat May 21 16:32:14 2011 (+0530) # Version: # Last-Updated: Sat May 21 17:54:05 2011 (+0530) # By: Ray jennings # Update #: 117 # URL: # Keywords: # Compatibility: # # # Commentary: # # # # # Change log: # # # # Code: ... ... ... # # join_proteins.py ends here

Thanks in Advance

Chakri

Replies are listed 'Best First'.
Re: How to do the follwing in Perl OR any other software
by graff (Chancellor) on Jun 25, 2011 at 01:07 UTC
    If I understand correctly, I think you want a template for writing new Perl scripts, rather than new Python scripts. Right? If so, I've found from my own experience that a template like the following is far more useful than the pattern shown in the OP.
    #!/usr/bin/perl =head1 NAME =head1 SYNOPSIS =head1 DESCRIPTION =head1 AUTHOR {your name and email address here} =cut use strict; use warnings; my $Usage = "Usage: $0 \n";
    I delete the $Usage line if I'm writing a module, or when I decide to go with "use Pod::Usage". The NAME, SYNOPSIS and DESCRIPTION sections always get filled in before I write any of the code. (There's probably a nifty way to have the NAME section initialized to the name of the file being edited -- that's an itch to be scratched...)

    I know there's a way in emacs to have a template file loaded into the editing buffer every time you start a new file with a given extension (e.g. *.pl or *.pm), but I'm content just to have the above template stored in an easy-to-find file, and do "meta-x include-file" every time I start a perl script.

Re: How to do the follwing in Perl OR any other software
by Corion (Patriarch) on Jun 24, 2011 at 20:18 UTC

    You don't show us what code you have already written and where you encounter problems with it.

    I can only suggest you look at Module::Starter and/or Template Toolkit. The two are common solutions for generating boilerplate text files.

Re: How to do the follwing in Perl OR any other software
by roboticus (Chancellor) on Jun 24, 2011 at 20:27 UTC

    chakreey:

    Most editors that I've seen have the ability to stick in a template, and there are a zillion others. But *just for you*, here's a perl script that'll generate a template for you:

    #!/usr/bin/perl my $new_file_name = shift; open my $OFH, '>', $new_file_name; print $OFH <<EOHDR; #!/usr/bin/env python # join_proteins.py --- # # Filename: $new_file_name # Description: # Author: Andy Bork # Maintainer: # Copyright (C) 2010 Andy Bork, all rights reserved. # Created: Sat May 21 16:32:14 2011 (+0530) # Version: # Last-Updated: Sat May 21 17:54:05 2011 (+0530) # By: Ray jennings # Update #: 117 # URL: # Keywords: # Compatibility: # # # Commentary: # # # # # Change log: # # # # Code: print "hello, world!\n"; print "Replace this section with the code you want.\n"; # # $new_file_name ends here EOHDR close $OFH;

    With just a few simple modifications, you can have it automatically put in current copyright dates and such.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thank you roboticus. I just came to know few key words for doing this, like "boilerplate". I googled "boilerplate" and found interesting links. I am reading on further to be able to do it myself.

      chakri

Re: How to do the follwing in Perl OR any other software
by Anonymous Monk on Jun 25, 2011 at 01:56 UTC