Today I completed a simple program to download stock pricing information. This Perl6 program takes a list of stock symbols and utilizes the Yahoo.com Finance WebService API and retrieves the current day's closing stock price. This data is then saved into a text file in my clDB database format.

Perl6 modules to the rescue
Using the HTTP::Tinyish Perl6 Module, I craft a HTTP Get request to the finance.yahoo.com WebService. In my request I state that I want the Name, stock symbol and the closing price for the current day to be returned for each stock listed.
I use the crontab service on my server to run the program every day at 1330 and grab the closing price for the stocks.
For now I have the output sent to a text file using the clDB data format. At this point I can use another program to analyze the data or even make an an SVG chart graphic. This will be a separate program I will work on latter.

Inside the Code
In this program I use the .trans
and .split
methods to clean up the data returned from the Yahoo.com WebService.
On line 25, @data = $line.trans(' " ' => '', :delete).split(",");
takes the current text in the $line
Variable and transliterats the quotes (") character and replaces it with nothing, basically removing it. Then using the .split
method, it takes that and splits it every time it finds a comma (,) character. The results end up as elements in the @data
array, which I then use when I craft the $dataString
which gets appended (Line 27) to the output file.
Transliterate is a very useful method provide by the Str class more info and examples can be found here at the Perl6 documentation page.
Sample output
The results of of the entire process can be seen on the page listed below.
View the results of the code here