L. Neil Johnson wrote:
> Thank you for responding. Sorry about the ambiguity. The main program is a
> sequence of computational processes that reads several files of 20K to 50K
> records and splits them into 12 parallel arrays of that length. Analytic
> routines generate an array (@trade) of 2K to 4K elements, each of which is a
> reference to an anonymous array of, say, 7 elements; built like so:
>
> for ($iS=1; $iS<=$#sigs; $iS++) {
> ... # processing...
> push(@trade,[$j,$i,"TaS",$sig,$amp,$elT,$tre[$j]]); # append trade to
> array
> }#for
> [0]begIx,[1]endIx,[2]indic,[3]type,[4]amplitude,[5]elapsedTime,[6]trend
>
> Further on, other processes access this data for analysis, and to build and
> print other arrays, like so:
>
> for ($i=1;$i<=$#trade;$i++) {
> ... # processing...
> push (@tCycle,
> [$j,$l,$m,$trade[$i]->[2],$phWin,$trade[$i-2+$sSC]->[4],
> $trade[$i]->[5]+$trade[$i-1]->[5],[EMAIL PROTECTED]);
> ... # processing...
> }#for
>
> A module was designed (TSP.pm), which contains two subroutines, one which
> prints descriptive statistics, and one which prints performance metrics for
> the
> @trade data. The subroutines, in general, access individual elements of the
> anonymous arrays, like so:
You could start that package off with a 'package main;' stmt which will
put you in the same namespace as the calling module.
> for ($i=0;$i<=$#{$rT};$i++) {
You can use an array's scalar context to make this easier to read :
for (my $i = 0; $i < @{$rT}; $i++) {
> ... # processing...
> $da = int(${$rD}[${$rT}[$i]->[0]]/86400)*86400; # $rT is ref to @trade
> ... # processing...
> }#for
# using constants (but you have to export them to the other module like
your glob refs):
use constant xbi => 0; # index into data arrays, begin time
use constant xei => 1; # index into data arrays, end time
use constant xi => 2; # indicator
use constant xs => 3; # signal
use constant xa => 4; # amplitude
use constant xt => 5; # elapsed time
use constant xr => 6; # trend
# no code change here
push @tCycle, [$j, $l, $m, $trade[$ii]->[$xi], $phWin,
$trade[$ii-2+$sSC]->[$xa], $trade[$ii]->[$xt] + $trade[$ii-1]->[$xt], [EMAIL
PROTECTED];
# using a hash:
my %IX = (
xbi => 0; # index into data arrays, begin time
xei => 1; # index into data arrays, end time
xi => 2; # indicator
xs => 3; # signal
xa => 4; # amplitude
xt => 5; # elapsed time
xr => 6; # trend
};
# $xi then becomes $IX{xi} :
push @tCycle, [$j, $l, $m, $trade[$ii]->[$IX{xi}], $phWin,
$trade[$ii-2+$sSC]->[$IX{xa}], $trade[$ii]->[$IX{xt}] +
$trade[$ii-1]->[$IX{xt}], [EMAIL PROTECTED];
> As mentioned previously, I got tired of editing the absolute indices (e.g.,
> $trade[$i]->[6]) every time the order or meaning of an element of the
> anonymous
> arrays changed; so in main I defined typeglobs:
>
> *xbi = \0; # index into data arrays, begin time
> *xei = \1; # index into data arrays, end time
> *xi = \2; # indicator
> *xs = \3; # signal
> *xa = \4; # amplitude
> *xt = \5; # elapsed time
> *xr = \6; # trend
>
> ...to allow the use of variables for the indices, like so:
>
> push (@tCycle,
> [$j,$l,$m,$trade[$i]->[$xi],$phWin,$trade[$i-2+$sSC]->[$xa],
> $trade[$i]->[$xt]+$trade[$i-1]->[$xt],[EMAIL PROTECTED]);
>
> My question is how best to get those typeglobs into the namespace of module
> TSP.pm so that, when I make a change, it's once in main, and the change is
> automatically propagated into TSP.pm. Right now, I just cut and paste the
> typeglobs from main into TSP.pm. Thank you.
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs