On Sep 28, 2005, at 4:38 PM, Michael Oliver wrote:
Its more than three lines, but tell me this,
Well, it could be less code if you knew you didn't need to deal with
redirects :)
But, to be safe, I'd guess it'd be 10 lines of clean Ruby code to do
this task... and 3 lines of Perl-esque garbage code if you wanted to
obfuscate it and compress it as much as possible.
Do you have to rub three times to get ruby to give you the magic?
Nope, only once. Ruby is just that sweet.
Erik
-----Original Message-----
From: Erik Hatcher [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 28, 2005 1:32 PM
To: jug-discussion@tucson-jug.org
Subject: Re: [jug-discussion] Why Jython, or Jelly, or Groovy, or
Beanshell
or ... instead of perl, or sh script?
On Sep 28, 2005, at 4:17 PM, Tim Colson (tcolson) wrote:
So if you were doing this task, how would you approach it? What tool
would you use? And more importantly, why?
I'd use Ruby, personally. It'd be much more readable than the
equivalent
Perl variant, almost for sure. The readability factors into the
maintainability too.
One way would be to leverage the Net::HTTP library:
<http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/>
I use it to fetch a string from an HTTP response this way:
# Fetch method copied from PickAxe, p. 700
def fetch(uri_str, limit=10)
fail 'http redirect too deep' if limit.zero?
response = Net::HTTP.get_response(URI.parse(uri_str))
case response
when Net::HTTPSuccess
response
when Net::HTTPRedirection
fetch(response['location'], limit - 1)
else
response.error!
end
end
fetch("http://www.ruby-lang.org") # for example, which would follow
the
redirect to /en
To pull binary content, you'll have to use the API slightly
differently, but
it'll still be pretty trivial.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]