#!/usr/bin/perl # Perl 5.x script for querying the secapl quote server # by Po Shan Cheah (cheah@nic.com) # Check http://www.nic.com/~cheah/quote.html for updates # # October 7, 1996: # added code for stocks (still messy) # added code to tell when the quote server does not # recognize a stock symbol # January 10, 1997: # connect retry # better stock data formatting # command line options for server, port, timeout # changed default server # December 4, 1997: # Disabled the alarm calls for Win32. use strict; use Socket; use Getopt::Std; BEGIN { # Uncomment the one you want as the default the two IP addresses # are equivalent to the host names as of January 10, 1997. At that # time, qs-alt was a little faster than qs. $::SERVER = 'qs-alt.secapl.com'; #$::SERVER = 'qs.secapl.com'; #$::SERVER = '192.131.69.9'; #$::SERVER = '207.79.173.10'; $::PORT = 80; $::TIMEOUT = 15; $::USAGE = <<"EOM"; Usage: $0 [-s server] [-p port] [-t timeout] symbol [symbol ...] -s Specify server to contact. Default: $::SERVER -p Specify tcp/ip port to contact. Default: $::PORT -t Specify timeout in seconds for connection retries. Default: $::TIMEOUT EOM $::iswin32 = $^O eq "MSWin32"; } # perform name and protocol resolution sub init { my(@hostinfo, @protoinfo); (@hostinfo = gethostbyname($::SERVER)) || die "gethostbyname error: $!\n"; (@protoinfo = getprotobyname('tcp')) || die "getprotobyname error: $!\n"; $::ipaddr = $hostinfo[4]; $::proto = $protoinfo[2]; } # Format left-aligned, right-aligned, and centered strings. sub left { my($width, $str) = @_; my($spaces) = $width - length $str; if ($spaces < 0) { $spaces = 0; } $str . " " x $spaces; } sub right { my($width, $str) = @_; my($spaces) = $width - length $str; if ($spaces < 0) { $spaces = 0; } " " x $spaces . $str; } sub center { my($width, $str) = @_; my($spaces) = $width - length $str; my($leftspaces); if ($spaces < 0) { $spaces = 0; } $leftspaces = int($spaces / 2); " " x $leftspaces . $str . " " x ($spaces - $leftspaces); } # The secapl server returns the stock data in a html
| entries so they won't get ignored. $stream =~ s/( | ]*>)(<\/TD>)/$1 $2/gi;
# print "$stream\n";
# Chop off everything except the stuff contained between the first
# |