#!/import/archperf/ws/devtools/4/amd64/bin/perl
eval 'exec /import/archperf/ws/devtools/4/amd64/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
library files to Perl5-style library modules. Usually, your old .pl
file will still work fine and you should only use this tool if you
plan to update your library to use some of the newer Perl 5 features,
It's just a first step, but it's usually a good first step.
Larry Wall <larry@wall.org>
$newname =~ s/\.pl$/.pm/ || next;
$newname =~ s#(.*/)?(\w+)#$1\u$2#;
warn "Won't overwrite existing $newname\n";
s/\bstd(in|out|err)\b/\U$&/g;
s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
@export = m/sub\s+\w+'(\w+)/g;
s/(sub\s+)main'(\w+)/$1$2/g;
@export = m/sub\s+([A-Za-z]\w*)/g;
my @export_ok = grep($keyword{$_}, @export);
@export = grep(!$keyword{$_}, @export);
@export{@export} = (1) x @export;
s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
s/open\s+(\w+)/open($1)/g;
s/croak "([^"]*)\\n"/croak "$1"/g;
$export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
if ( open(PM, ">$newname") ) {
warn "Can't create $newname: $!\n";
my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
$xlated = "${pack}'$ident";
elsif ($pack eq '' || $pack eq 'main') {
$xlated = "$prefix$ident";
$xlated = "$prefix${pack}::$ident";
elsif ($pack eq $oldpack) {
$xlated = "$prefix${newpack}::$ident";
$xlated = "$prefix${pack}::$ident";