inspired by Module Version Number?, this utility will generate the beginnings of a perl script, with use statements for modules passed via command-line, including module versions and null import lists.

for example, saving the script as perlgen.pl, and running with perlgen.pl CGI DBI Win32::Shortcut will produce:

#!/usr/bin/perl require 5.006_001; use strict; use warnings; $|++; ## generated by perlgen.pl: 0.01 use CGI 2.752 qw//; use DBI 1.15 qw//; use Win32::Shortcut 0.03 qw//;

improvements left for the reader

#!/usr/bin/perl require 5.006_001; use strict; use warnings; $|++; our $VERSION = 0.01; ## generate a perl script header ## print generic header print <<"EOH"; #!/usr/bin/perl require 5.006_001; use strict; use warnings; \$|++; ## generated by $0: $VERSION EOH ## print out versions of modules for( @ARGV ) { eval "require $_"; no strict 'refs'; my $modVersion = ${$_ . '::VERSION'} || ''; print "use $_ ", $modVersion, ' qw//;', $/; }

Replies are listed 'Best First'.
Re: generate a perl script header
by jdavidboyd (Friar) on Nov 04, 2002 at 14:00 UTC
    When I run it I get:

    Use of uninitialized value in print at ./gen_perl_script_header.plx line 28.

    Dave

      whoops! it seems if the module doesn't have a $VERSION variable, you'll run into this problem. i've patched the code to get around this limitation.

      ~Particle *accelerates*