Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created November 22, 2012 18:27
Show Gist options
  • Select an option

  • Save vkgtaro/4132481 to your computer and use it in GitHub Desktop.

Select an option

Save vkgtaro/4132481 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use File::Find;
use IO::File;
File::Find::find({ wanted => \&wanted, no_chdir => 1}, '.');
sub wanted {
my $path = $File::Find::name;
if (-f $path && $path =~ m{\.html\z}xms) {
printf STDERR "[start] %s\n", $path;
my $text = slurp($path);
$text = replace_ssi_tag($text);
write_file($path, $text);
printf STDERR "[end] %s\n", $path;
}
}
sub replace_ssi_tag {
my ($text) = @_;
$text =~ s{\#INCLUDE \s+ VIRTUAL}{# include virtual}xms;
return $text;
}
sub slurp {
my ($path) = @_;
my $fh = IO::File->new($path, 'r') or die "Can't read $path: $!";
local $/ unless wantarray;
return <$fh>;
}
sub write_file {
my ($path, $text) = @_;
my $fh = IO::File->new($path, 'w') or die "Can't read $path: $!";
$fh->print($text);
$fh->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment