Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Finance::Quote woes

by tekniko (Deacon)
on Oct 16, 2002 at 14:35 UTC ( [id://205728]=perlquestion: print w/replies, xml ) Need Help??

tekniko has asked for the wisdom of the Perl Monks concerning the following question:

I use the following, taken directly from the Finance::Quote site, to check securities. If I attempt to check a mutual fund, such as JAVLX, I get the error:

Use of uninitialized value in printf at quote.pl line67.

Any thoughts? Could it be the length of the stock symbol?

#!/usr/bin/perl -w # # Stock-ticker program. # Can look up stocks from multiple # markets and return the results in # local currency. use strict; use Finance::Quote; my $CURRENCY = "USD"; # Set preferred currency here, or empty strin +g for # no conversion. # The stocks array contains a set of array-references. Each reference # has the market as the first element, and a set of stocks thereafter. my @STOCKS = ([qw/australia CML ITE BHP/], [qw/usa MSFT RHAT LNUX AW UDW VICM CSCO NWRE MLM CBYI ROK HD +I LU AMZN INRG LMT LOR DELL INTC CCI QQQ YHOO USAI LVLT SPW AZPN ITWO + AKLM/] ); # These define the format. The first item in each pair is the label, # the second is the printf-style formatting, the third is the width # of the field (used in printing headers). my @labels = (["name", "%12s", 15], ["date", "%11s", 11], ["time", "%10s", 11], ["last", "%8.2f", 8], ["high", "%8.2f", 8], ["low", "%8.2f", 8], ["close", "%8.2f", 8], ["volume","%10d", 10]); my $REFRESH = 120; # Seconds between refresh. # --- END CONFIG SECTION --- my $quoter = Finance::Quote->new(); my $clear = `clear`; # So we can clear the screen. # Build our header. my $header = "\t\t\t\tSTOCK REPORT" .($CURRENCY ? " ($CURRENCY)" : "") + ."\n\n"; foreach my $tuple (@labels) { my ($name, undef, $width) = @$tuple; $header .= sprintf("%".$width."s",uc($name)); } $header .= "\n".("-"x79)."\n"; # Header is all built. Looks beautiful. $quoter->set_currency($CURRENCY) if $CURRENCY; # Set default curren +cy. for (;;) { # For ever. print $clear,$header; foreach my $stockset (@STOCKS) { my ($exchange, @symbols) = @$stockset; my %info = $quoter->fetch($exchange,@symbols); foreach my $symbol (@symbols) { next unless $info{$symbol,"success"}; # Skip failures. foreach my $tuple (@labels) { my ($label,$format) = @$tuple; printf $format,$info{$symbol,$label}; } print "\n"; } } sleep($REFRESH); } __END__

Replies are listed 'Best First'.
Re: Finance::Quote woes
by valdez (Monsignor) on Oct 16, 2002 at 15:10 UTC

    I think the problem is: JAVXL quotes, as returned by Finance::Quote, haven't all the fields you try to access and perl complains about this. The field that causes the error should show under VOLUME column.

    A solution is to check if this field is defined...

    Ciao, Valerio

      Ah...That's it! Thanks!
Re: Finance::Quote woes
by ignatz (Vicar) on Oct 16, 2002 at 14:49 UTC
    Runs fine for me on my Linux server. I did note that it doesn't have a test file in the install package and that it requires HTML::TableExtract. Might want to make sure that you installed that. Using CPAN or better yet CPANPLUS to install catches stuff like that if that's the problem. (Wouldn't generate that error, though. ) Perhaps it's a connectivity issue?

    (ADDED:) Some hardware/software details might help track this down.

    ()-()
     \"/
      `                                                     
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://205728]
Approved by ignatz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found