Debunking Stroustrup's debunking of the myth “C++ is for large, complicated, programs only”
Wolfram
This feels like complete cheating
Import["http://www.stroustrup.com/C++.html", "Hyperlinks"]
So just add some honest parsing on top
Cases[
Import["http://www.stroustrup.com/C++.html", "XMLObject"],
XMLElement["a", {___, "href" -> link_, ___}, ___] :>
link /; StringMatchQ[link, RegularExpression["((http://)?www([./#\\+-]\\w*)+)"]]
, Infinity]
C++
#include <boost/asio.hpp>
#include <regex>
#include <iostream>
int main() {
std::string server = "www.stroustrup.com";
std::string request = "GET http://" + server + "/C++.html HTTP/1.0\r\nHost: " + server + "\r\n\r\n";
boost::asio::ip::tcp::iostream s{server, "http"};
s << request;
std::regex pat{R"((http://)?www([./#\+-]\w*)+)"};
std::smatch m;
for (std::string l; getline(s, l);)
if (std::regex_search(l, m, pat))
std::cout << m[0] << "\n";
}
The main shortcoming is the awkward nature of boost::asio, I'm sure it can be even shorter with a better library.
Pure Bash on Linux/OS X (no external utilities)
HTTP client software is notoriously bloated. We don't want those kinds of dependencies. Instead we can push the appropriate headers down a TCP stream and read the result. No need to call archaic utilities like grep or sed to parse the result.
domain="www.stroustrup.com"
path="C++.html"
exec 3<> /dev/tcp/$domain/80
printf "GET /$path HTTP/1.1\r\nhost: %s\r\nConnection: close\r\n\r\n" "$domain" >&3
while read -u3; do
if [[ "$REPLY" =~ http://[^\"]* ]]; then
printf '%s\n' "$BASH_REMATCH"
fi
done
Meh - I suppose it could be more readable...