------------------------------------------------
On Tue, 29 Jul 2003 09:41:01 -0400, "West, William M" <[EMAIL PROTECTED]> wrote:

<snip>

> >> i tried for the longest time to get something like
> >> the following to work::
> >>
> >> foreach $section (keys %board){
> >>
> >

<snip>

> 
> it was an error in my logic- i was using a hash reference as if it were a
> hash (i do not always write as clearly as i should *laugh*)
> 
> if i start using $board as a hash reference without a %hash assigned to it-
> then that foreach statement above .. " foreach $section (keys %board)"
> wouldn't work -- i had to creat %board first!  it took me forever to get
> that through my head!
> 

You are correct in a roundabout sort of way. You have to have a hash in the foreach 
(or more to the point any time you call keys) but that hash can be created on the fly 
by directly dereferencing the reference rather than doing it before hand, so the 
following will both work the same:

$board = { 'key1' => 'val1', 'key2' => 'val2' };

foreach my $key (keys %$board) {
}

-or the more verbose and more memory intensive-
%board = %$board;
foreach my $key (keys %board) {
}

The key is that $board (no matter what it contains) and %board are two very separate 
variables. $board can be a reference to %board but is NOT automatically, it is only 
one when you have explicitly told it to be.

The docs posted earlier should "clear" things up, at least until they make you want to 
learn more at which time it will probably be fogging again for a while :-) .......

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to