-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquote.pl
67 lines (47 loc) · 1.19 KB
/
quote.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
=pod
=head1 NAME
quote.pl - Get a stock quote from the Internet
=head1 SYNOPSIS
quote.pl <symbol> [<symbol> ...]
=head1 DESCRIPTION
The I<quote.pl> gets stock information from the Yahoo finance site.
=head1 EXAMPLES
quote.pl GOOG
GOOG Last: 293.50 Day range: 293.28 - 297.41
Year range: 95.96 - 317.80
=head1 AUTHOR
Steve Oualline, E<lt>[email protected]<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
use strict;
use warnings;
use Finance::Quote;
if ($#ARGV == -1) {
print STDERR "Usage is $0 <stock> [<stock> ...]\n";
exit (8);
}
# Get the quote engine
my $quote = Finance::Quote->new;
# Get the data
my %data = $quote->fetch('usa', @ARGV);
# Print the data
foreach my $stock (@ARGV) {
my $price = $data{$stock, "price"};
if (not defined($price)) {
print "No information on $stock\n";
next;
}
my $day = $data{$stock, "day_range"};
my $year = $data{$stock, "year_range"};
if (not defined($day)) {
$day = "????";
}
if (not defined($year)) {
$year = "????";
}
print "$stock Last: $price Day range: $day\n";
print "Year range: $year\n";
}