Hi Wiggins, Thank you for your reply. I will go and use the Finance::Quote::ASX module. For now though this problem is really bugging me and for my own sake I would like to get it to work. I have declared all my variables and am using warnings and strict. Unfortunarly I am still only able to print the last set of keys and values of my hash of hash outside of the foreach loop. Any other ideas? Kind regards, Dan -----Original Message----- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, 25 June 2004 11:55 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Printing outside of foreach...
> Hello again, > > The folling code takes some data from the Australian Stock Exchage > website. The problem I am having is that I need to be able to access > the hash of the hash outside of the foreach statement. So in other > words I would like to be able to access areas within the hash > %stock_hash any where in my script. I take it I need Perl to store > the hash $stock_hash into memory and remember it. Am I on the right > track here? > Well not to burst any bubbles, especially if this is a learning exercise, but have you considered using the Finance::Quote suite of modules? It appears there is a Finance::Quote::ASX for accessing quotes from the Australian Stock Exchange. It is available from CPAN and has worked very well for me in the past (well not the ASX one but the others). > At the moment the hash %stock_hash will print exactly what I want > within the foreach statement. > > Kind Regards, > > Dan > are you using 'strict' and 'warnings'? Doesn't look like it, you should. > foreach $stock (@stocks) { > > my $html_string = > get("http://www.asx.com.au/asx/markets/PriceResults.jsp?method=get&tem > pl > ate=F1001&ASXCodes=$stock"); > > $te = new HTML::TableExtract( headers => [qw(Code Last \$)] ); > $te->parse($html_string); # Examine all matching tables > foreach $ts ($te->table_states) { > # print "Table (", join(',', $ts->coords), "):\n"; > foreach $row ($ts->rows) { > join (',', @$row); > @downloaded_stocks = @$row; > } > %stock_hash = ( > $downloaded_stocks[0] => { > "Trading Price" => "\$$downloaded_stocks[1]", > "Price Change" => "\$$downloaded_stocks[2]", > }, > ); Right here you can store a reference to %stock_hash into another data structure, possibly a hash based off of the exchange+ticker. The other data structure should be "globally" scoped. perldoc perldsc perldoc perllol perldoc perlreftut perldoc perlref > for $code ( sort keys %stock_hash ) { > print "$code: "; > for $details ( sort keys %{ $stock_hash{$code} } ) { > print "$details=$stock_hash{$code}{$details} "; > } > print "\n"; > } > } > } > HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>