#!/opt/default/bin/perl -w

require 5.002;
use strict;
use sigtrap;
use Socket;

$, = ' ';

my ($q, $stock, $x, $remote, $port, $iaddr, $paddr, $proto, $line);

$stock = shift || "LU+MSFT+T";
$remote = shift || 'quote.yahoo.com';
$port = 80;
$iaddr = inet_aton($remote);
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');

# /index.html
# http://quote.yahoo.com/q?s=t+lu+msft&d=v1&o=t

$q = "/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv";  
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect(SOCK, $paddr) or die "connect: $!";
$x = "GET $q HTTP/1.0\r\n\r\n";

syswrite(SOCK, $x, length($x));
$line = "";
while (<SOCK>) {
	$line .= $_;
}
close(SOCK);

### $line =~ tr/[A-Z]/[a-z]/;	# lower case
#$line =~ s/<\/?[^>]+>//g;	# zap <...>
#$line =~ s/\&\w+;//g;		# zap &nbsp; etc
#$line =~ s/\n+/\n/g;		# coalesce blank lines
print $line;
