Please reply to the group so others can help/learn for this. Can you send the rest of the code? that oks.
Paul
On Sat, Jun 26, 2004 at 12:31:09AM +0930, Daniel Falkenberg wrote:
> Hi Paul,
>
> Thank you for yur reply. I have declared %stock_hash and I still can't
> print all of the results outside the foreach loop. I still have ...
>
> %stock_hash = (
> > $downloaded_stocks[0] => {
> > "Trading Price" => "\$$downloaded_stocks[1]",
> > "Price Change" => "\$$downloaded_stocks[2]",
> > },
>
> ... Inside the loop. Is this all correct?
>
> Regards,
>
> Dan
>
> -----Original Message-----
> From: Paul Kraus [mailto:[EMAIL PROTECTED]
> Sent: Friday, 25 June 2004 10:28 PM
> To: Daniel Falkenberg
> Subject: Re: Printing outside of foreach...
>
>
> Declare the variable before the foreach statement.
>
> my %stock_hash;
> foreach ....
>
> this will leave the data for stock_host available to at least the block
> before the foreach.
>
> HTH,
> Paul
> On Fri, Jun 25, 2004 at 02:22:29PM +0930, Daniel Falkenberg wrote:
> > 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?
> >
> > At the moment the hash %stock_hash will print exactly what I want
> > within the foreach statement.
> >
> > Kind Regards,
> >
> > Dan
> >
> > 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]",
> > },
> > );
> > for $code ( sort keys %stock_hash ) {
> > print "$code: ";
> > for $details ( sort keys %{ $stock_hash{$code} } ) {
> > print "$details=$stock_hash{$code}{$details} ";
> > }
> > print "\n";
> > }
> > }
> > }
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > <http://learn.perl.org/> <http://learn.perl.org/first-response>
> >
pgpOYNx2uyq1H.pgp
Description: PGP signature
