Article -- Perl: Creating a Stock Alert Program
Creating a Program in Perl to Check Stock Prices
This is a simple example of how to use the CPAN module Finance::Quote to check stock prices then diplay a result if they are not in a specific range.
This program reads from a text file in the following format.
"exchange", "symbol", "highprice", "lowprice"
"nasdaq", "GOOG", "300", "280"
#!/usr/bin/perl # use Finance::Quote; $q = Finance::Quote->new; open(INFILE, "./stocks.txt") or die; while() { @List = split(/,/, $_); @StockNames = split(/\"/, $List[1]); @StockXchange = split(/\"/, $List[0]); @High = split(/\"/, $List[2]); @Low = split(/\"/, $List[3]); %quotes = $q->fetch($StockXchange[1],$StockNames[1]); if($quotes{$StockNames[1], "last"} > $High[1]) { print "$StockNames[1] is too high\n"; } if($quotes{$StockNames[1], "last"} < $Low[1]) { print "$StockNames[1] is too low\n"; } }
»
- Login to post comments
