Split pod documentation from a Perl module

This Perl script splits the file name on its command line into .pm and .pod parts. The files are given a temporary name using the process number ($$).

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use File::Slurper qw/read_text write_text/;
if (! @ARGV) {
    usage ();
}
for my $file (@ARGV) {
    if (! -f $file) {
        warn "No such file '$file'";
        next;
    }
    my $text = read_text ($file);
    my $pod = '';
    while ($text =~ s!(^=(head|encoding|pod).*?)=cut$!!sm) {
        $pod .= "$1\n";
    }
    my $podout = "$file.pod.$$";
    my $pmout = "$file.pm.$$";
    write_text ($pmout, $text);
    write_text ($podout, $pod);
}
exit;

sub usage
{
    print <<EOF;
$0 - split a Perl module into Perl and Pod files

Usage:

$0 <file1> <file2>

The output is the name of the files with a random number attached.
EOF
}

(download)

At my blog post about this topic, commentators note that


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer