On Thursday, June 30, 2005 1:25 AM, $Bill Luebkert [SMTP:[EMAIL PROTECTED] 
wrote:
>
> You could start that package off with a 'package main;' stmt which will
> put you in the same namespace as the calling module.

Good idea.  This obviates the need to import identifiers. Rob suggested a 
similar approach yesterday.

> You can use an array's scalar context to make this easier to read :
>       for (my $i = 0; $i < @{$rT}; $i++) {

Thanks for the coding critique. You're right.  Any idea if either form 
evaluates faster? $#array or scalar @array?

> # 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

I prefer this approach, notwithstanding the need to copy the definitions into 
the module(s) that use them: 1) The indices really are constants, and the 
pragma makes that clear. 2) Dropping the "$" from the symbol in the anonymous 
array index makes it clear when reading the body of the code that the index 
isn't going to change (I probably would use all caps in the identifiers to 
emphasize this). 3) The identifiers are shorter by one character. 4) If the 
compiler in-lines the constant (or subroutine that coughs up the constant), it 
may execute faster.

> # 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
> };

This is also a good idea in that the identifiers are passed with the array, and 
there's no need to define them in each module.  However, Johanes Lindstrom's 
method of using anonymous hashes appeals to me because it's so natural to read.

Bill, I really appreciate your commentary on the code and the expert 
suggestions you have made -- as usual.

-Neil

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to