Created
March 19, 2010 08:35
-
-
Save fujiwara/337350 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use HTTP::Request::Common; | |
my $host = "fujiwara-mac"; | |
my $port = 9292; | |
my $file = shift; | |
my $in; | |
my $content = (open $in, "<", $file) | |
? do { local $/; <$in> } | |
: ""; | |
close $in; | |
my $ua = LWP::UserAgent->new( timeout => 0 ); | |
my $req = $ua->request( PUT "http://$host:$port/edit", Content => $content ); | |
if ($req->code == 200) { | |
rename "$file", "${file}~"; | |
open my $out, ">", $file or die $!; | |
print $out $req->content; | |
exit; | |
} | |
else { | |
die $req->status_line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment