Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created March 19, 2010 08:35
Show Gist options
  • Save fujiwara/337350 to your computer and use it in GitHub Desktop.
Save fujiwara/337350 to your computer and use it in GitHub Desktop.
#!/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