[Wellington-pm] Strange (for me) notation
Chris Eade
chris.eade at gmail.com
Tue Jul 21 17:09:10 PDT 2009
Awesome!
Thanks for that - thats much clearer now. I will definitely be
changing it, so any future unlucky punter doesn't encounter it too.
Cheers, and I hope everything is going well - including the boat! I
have made some progress, but not far enough to have reached water yet
:)
Chris.
On Wed, Jul 22, 2009 at 11:23 AM, Grant McLean<grant at mclean.net.nz> wrote:
> Hi Chris!
>
> It's been so quiet here without you :-)
>
> On Wed, 2009-07-22 at 11:10 +1200, Chris Eade wrote:
>> ... this particular piece of code has me really stumped. It looks
>> like this:
>>
>> use constant LATEST_D_ACROSS_PRODUCTS => 'P';
>> <snip>
>> $ib->{reg}->{@{[LATEST_D_ACROSS_PRODUCTS]}} = $ed;
>> $ib->{prodNo}->{@{[LATEST_D_ACROSS_PRODUCTS]}} .= "$product_no,";
>
> The problem is if they just did ...
>
> $ib->{reg}->{LATEST_D_ACROSS_PRODUCTS} = $ed;
>
> Then LATEST_D_ACROSS_PRODUCTS would be interpreted as the string
> 'LATEST_D_ACROSS_PRODUCTS'.
>
>>
>> The part I really don't get is the meaning of this:
>>
>> @{[LATEST_D_ACROSS_PRODUCTS]}
>
> Yeah that's pretty awful. Putting [ .. ] around the constant creates an
> arrayref, putting @{ .. } around that dereferences the array ref back to
> a list of all its values.
>
> Since a Perl constant is really a subroutine (that gets optimised away),
> alternative approaches are:
>
> $ib->{reg}->{LATEST_D_ACROSS_PRODUCTS()} = $ed;
>
> or:
>
> $ib->{reg}->{&LATEST_D_ACROSS_PRODUCTS} = $ed;
>
> Cheers
> Grant
>
>
> _______________________________________________
> Wellington-pm mailing list
> Wellington-pm at pm.org
> http://mail.pm.org/mailman/listinfo/wellington-pm
>
More information about the Wellington-pm
mailing list