Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created August 16, 2012 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/3365227 to your computer and use it in GitHub Desktop.
Save tadzik/3365227 to your computer and use it in GitHub Desktop.
sub getfile($src, $dest) {
pir::load_bytecode__vs('LWP/UserAgent.pir');
Q:PIR {
.local string what, where
$P0 = find_lex '$src'
what = repr_unbox_str $P0
$P0 = find_lex '$dest'
where = repr_unbox_str $P0
ua = new ['LWP';'UserAgent']
response = ua.'get'(what)
$I0 = response.'code'()
if $I0 == 200 goto success
$I0 = 0
goto end
success:
outfile = new ['FileHandle']
outfile.'open'(where, 'w')
$S0 = response.'content'()
outfile.'print'($S0)
outfile.'close'()
$I0 = 1
end:
%r = $I0
} or die;
}
sub MAIN($src, $dest) {
getfile($src, $dest).perl.say;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment