And I think what he's saying (and I agree) is that 99% of the time, when somebody has a "I am limited to Perl distribution modules" restriction, it's an artificial limitation imposed by people that either don't understand what modules are or just don't understand what's involved in installing them.
Because, face it, if you have the means to mass-distribute your code, it's trivial to go one step further and mass-distribute modules with it. 99% of the time, this limitation is non-sensical, so people tend to keep repeating, "You're better off finding a way to distribute a pre-existing module that does the work you're wanting to do."
Look how easily LWP can do this:
use LWP::Simple;
my $content = get("http://www.example.com/some/page");
| [reply] [d/l] |
True... but that way only saves me 4 lines of code from your previous suggestion (which works very well, by the way), but then adds the 507K worth of LWP's code which I won't be using. If I can do it in 6 lines without LWP, and save myself the inconvenience of explaining to the users how to get the LWP module working, I have succeeded. LWP is more robust, but that's robustness I don't need for this purpose, I need quick and easy.
Alan "Hot Pastrami" Bellows
| [reply] |
| [reply] |
And it also handles redirections correctly, it also supplies the HTTP/1.1 "Host:" header automatically, it also correctly parses HTTP/1.1 responses ("chunked" encoding types, etc.), and it automatically knows when an error condition occurs (the result will be undefined). It should detect when the resulting data was cut off in mid-stream, it will not hang indefinitely waiting for a response. It doesn't require that you know HTTP or understand what HTTP headers are. It also will do form POSTs with a very minor change.
If that's all stuff that you don't need, then you're right, you're fine going with a bare-bones IO::Socket method.
You shouldn't have to explain to anybody how to get some magic module working. Just copy the stuff over along with your script. That's what I mean when I say it's really trivial to extend a typical distribution method just one step further to include a module. And you are also right, this is a pretty trivial thing to implement without a module, but more often than not, the request is for something a bit more complicated (like parsing HTML). In cases like that, it's usually pretty easy to get something that works for the most extreme basic cases, but anything at all that falls outside of that case (HTML tags spanning lines, for example, or encompassing brackets in the tag) will break their algorithm, they end up having to do a lot more work to fix their broken code, and they end up with some monstrous piece of garbage that could have been simplified to nothing by using pre-written modules.
I realize that this doesn't necessarily apply to you, but I'm trying to explain why those people in this thread that are incessantly recommending the installation of a real module to do the job are doing that.
| [reply] |
I'm not sure if LWP is included in ActivePerl by default... I've installed it from CPAN, so it's there on mine now. If you're right then I'm dumb.
Alan "Hot Pastrami" Bellows
| [reply] |