On Jun 24, 2004, at 11:52 PM, 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.

Have you tried using it outside the loop? I suspect it will work.

Unfortunately, if it does, it points to a bigger problem. You're probably not using "strictures". That's a bad habit and one you want to get out of quickly.

use strict;
use warnings;

Those two lines belong at the top of all your scripts until you understand them enough to say why they don't. Together, they represent a deal between you and perl. You promise to be a good programmer and perl promises to reward you by being a helpful compiler. That's a good deal.

If you add these lines to your code and it stops working, you probably just need to declare your variables before you use them.

my $variable;  # declaration

my @names = qw(Bob Jan Steve);  # declaration with initialization

Now, when you are doing this, your hash will probably stop being available outside your loop (if you declare it inside). The easy fix is just to declare it before the loop, so you can use it inside and after.

Hope that helps.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to