Your code worked for me. I used it to look up Google's stock, and got a correct value of 390.

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


In reply to Re: Finance::Quote; and foreach by bowei_99
in thread Finance::Quote; and foreach by mtaivalmaa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.