in reply to Referencing an array in a complex hashed data structure

So ... I am lost the forest of braces and brackets...

Then for goodness sake, use some horizontal whitespace!. Ie. spaces.

The only place you've used any is between the function name join, and its open paren where is is completely useless as the paren forms a natural delimiter!

The same snippet with some added makes it easy to see the problems:

sub reportWA{ # $key my $key = shift; my $NewWA; unshift @{ WA{ $key }{ stags } }, $WA{$key}{PT}; unshift @{ $WA{ $key }{ stags } }, $WA{$key}{PT}; $NewWA = $WA{ $key }{ PT }; $#{ @{ WA{ $key }{ stags } } } = $rnds-1; for my $i ( 1 .. $rnds -1 ){ ${ WA{ $key }{ stags } }[ $i ] *= $wght; $NewWA += ${ WA{ $key }{ stags } }[ $i ]; } #plog sprintf "stages = %s" ,join (", ",@stags); $NewWA /= $rnds; printf " %d %d %8.2f %s\n" , $key, $WA{ $key }{ PE }, $NewWA, join( ", ", @{ WA{ $key }{ stags } } ); }

The same with the errors highlighted:

sub reportWA{ # $key my $key = shift; my $NewWA; unshift @{ $WA{ $key }{ stags } }, $WA{$key}{PT}; #............^ $NewWA = $WA{ $key }{ PT }; $#{ @{ WA{ $key }{ stags } } } = $rnds-1; #........^ ......missing $ for my $i (1..$rnds-1){ ${ WA{ $key }{ stags } }[ $i ] *= $wght; #......^...missing $ $NewWA += ${ WA{ $key }{ stags } }[ $i ]; #................^..........missing $ } #plog sprintf "stages = %s" ,join (", ",@stags); $NewWA /= $rnds; printf " %d %d %8.2f %s\n" , $key, $WA{ $key }{ PE }, $NewWA, join( ", ", @{ WA{ $key }{ stags } } ); #.............................^......missing $ }

There may be more errors, but once you fixed those, there'll be less noise from the compiler that should allow you to see what's going on.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Referencing an array in a complex hashed data structure
by Wiggins (Hermit) on Dec 08, 2008 at 20:17 UTC
    There was another run-time error. But for closure, the program is executing and I am listing the end result below.

    The key was realizing the the anon array was really a reference to an anon array, which clicked in the dereference mode of thought ...

    if (!defined $WA{$key}) { { lock $WAlock; $WA{$key} = &share({}); #hook shared anon hash; { lock %{$WA{$key}}; $WA{$key}{PS}=$dtg; # PS period Start $WA{$key}{PE}=$dtg + $secs; # PE period End $WA{$key}{PT}=0; # PT period Total $WA{$key}{stags} = &share([]); for my $i (0..$rnds-1){ ${$WA{$key}{stags}}[$i]=0; # init all stages to 0 } } } } # end of (! defined) entry being initialized .... and ..... sub reportWA{ # $key my $key = shift; my $NewWA; unshift @{$WA{$key}{stags}}, $WA{$key}{PT}; $NewWA=$WA{$key}{PT}; # $periodTotal * 1 $#{$WA{$key}{stags}} = $rnds-1; for my $i (1..$rnds-1){ ${WA{$key}{stags}}[$i] *= $wght; #stg[n] = initial * (wght**n) $NewWA += ${WA{$key}{stags}}[$i]; } #plog sprintf "stages = %s" ,join (", ",@stgs); $NewWA /= $rnds; printf " %d %d %8.2f %s\n" , $key,$WA{$key}{PE} ,$NewWA, join (", ",@{$WA{$key}{stags}}); }
    Thank you all, and the speed was amazing..