To create static versions of pages that get hit from the outside, I wrote this program, which runs as a cron job. It parses the .htaccess file of the webserver and creates static HTML versions of the pages listed in the .htaccess file. Currently, there is no parsing so that the redirect from the .htaccess gets generated as the output file, but as entries into the .htaccess file get made by another script, that's not as problematic.
#!/usr/bin/perl -w
use strict;
use File::Basename;
use LWP::Simple;
use Getopt::Long;
GetOptions(
'wwwroot:s' => (\my $wwwroot),
'staticdir:s' => (\my $outdir),
'server:s' => (\my $server),
'node:i' => (\my @nodes),
'htaccess:s' => (\my $htaccess),
'savepath:s' => (\my $savepath),
);
$wwwroot ||= './public_html';
#$htaccess ||= "$wwwroot/.htaccess";
$server ||= "perlmonks.org";
$savepath ||= $wwwroot;
my $uri = "http://$server?node_id=%d;style=static";
my $save = "$savepath/%d.html";
# -d $wwwroot or die "wwwroot: '$wwwroot' is no directory.";
-d $savepath or die "savepath: '$savepath' is no directory.";
if (! scalar @nodes) {
open my $hta, "<", $htaccess
or die "Couldn't read '$htaccess' : $!";
push @nodes, map { /^\s*RewriteCond %\{QUERY_STRING\} node_id=(\d+)\$/ ? $1 : () } <$hta>;
};
for my $node (@nodes) {
my $url = sprintf $uri, $node;
my $target = sprintf $save, $node;
print "Saving $node via $url to $target";
printf ", %d\n", mirror($url, $target);
};
Are you trying to force the references into list context with the parentheses? It won't work. Are you using the parentheses because [doc://my] takes a list and will affect subsequent list members? It doesn't:GetOptions( 'wwwroot:s' => (\my $wwwroot), 'staticdir:s' => (\my $outdir), 'server:s' => (\my $server), 'node:i' => (\my @nodes), 'htaccess:s' => (\my $htaccess), 'savepath:s' => (\my $savepath), );
$ perl -Mwarnings -Mstrict -e' my $x, $y;' Parentheses missing around "my" list at -e line 1. Global symbol "$y" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
perlmonks.org content © perlmonks.org and Corion, jwkrahn
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03