in reply to Finance::Quote; and foreach
I think your problem lies in your file - for some reason, perl isn't reading in the values from the file as you expect it would. Since you (and I) hard code a variable, and it works fine, plus the fact that I don't know what your /scripts/test.txt file looks like, I suspect it's something with that file.
Here's the code I got to work, with comments. I included some code you can run to help confirm if it's reading in the contents of the file correctly.
#!/usr/bin/perl use Finance::Quote; use Carp; # This should give you more info if it couldn't read the file open SLIST, <, "/scripts/test.txt" or croak "Cannot open file - $!\n"; @stocks = <SLIST>; close (SLIST); # This will confirm that the stocks read in from the file are # what you expect print "Checking stocks: "; for my $stock (@stocks) { print "$stock "; } print "\n"; # the following code (uncommented) worked fine for me. # It got google's stock quote correctly #@stocks = ("GOOG"); $q = Finance::Quote->new; $cc = 'usa'; $symb = 'WTVN.PK'; # What is this used for? If not needed, good to d +elete it %myhash = $q->fetch($cc,@stocks); foreach $ans (@stocks){ print $ans ."-". $myhash{$ans,'price'}; }
-- Burvil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finance::Quote; and foreach
by runrig (Abbot) on Apr 03, 2006 at 16:29 UTC |