February 2006
Intermediate to advanced
304 pages
6h 16m
English
Anyone who's invested in stocks wants to know how their portfolio is doing. This script goes to the Internet and fetches the latest quotes for any given company.
1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 use Finance::Quote; 6 7 if ($#ARGV == -1) { 8 print STDERR "Usage is $0 <stock> [<stock>...]\n"; 9 exit (8); 10 } 11 12 # Get the quote engine 13 my $quote = Finance::Quote->new; 14 15 # Get the data 16 my %data = $quote->fetch('usa', @ARGV); 17 18 # Print the data 19 foreach my $stock (@ARGV) { 20 my $price = $data{$stock, "price"}; 21 if (not defined($price)) { 22 print "No information on $stock\n"; 23 next; 24 } 25 my $day = $data{$stock, "day_range"}; 26 my $year = $data{$stock, "year_range"}; ...Read now
Unlock full access