Created
November 22, 2012 18:27
-
-
Save vkgtaro/4132481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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