#18 Getting Stock Quotes

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.

The Code

 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"}; ...

Get Wicked Cool Perl Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.