From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Greg Sabino Mullane <greg(at)turnstep(dot)com> |
Cc: | pgsql-patches(at)postgresql(dot)org |
Subject: | Re: Small plperl documentation patch |
Date: | 2005-10-19 14:40:42 |
Message-ID: | 43565AEA.4070803@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Greg Sabino Mullane wrote:
>Tom Lane asked:
>
>
>
>>Please, tell me that isn't so. $a is a reserved name now? What was
>>Larry thinking?
>>
>>
>
>It's not that bad, really. $a and $b have special meaning inside of
>a sort subroutine as the two items being compared. Thus, you can write
>something like this:
>
>my @crooks = sort { lc $a cmp lc $b } @whitehouse;
>
> to create a list sorted by lowercase (albeit not in the most efficient
>matter). This will work even with "use strict" turned on, as $a and $b
>will not trip Perl's strict-mode checking of undeclared variables. So,
>the danger is very minor, but it's a good practice to not use them for
>temporary variables in a script.
>
>
>
>
I recently lost quite some time tracking down a piece of spurious data
persistence that eventually turned out to be due to use of an undeclared
$a that strict mode failed to detect, so it's not so minor, really.
In retrospect, the choice of names for sort comparison operands was
poor, as I suspect Larry would agree, but it's been there ever since I
have been using perl (around 12 years now, iirc).
cheers
andrew
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2005-10-20 05:05:37 | Error in ORDER BY on check constraints in psql |
Previous Message | Greg Sabino Mullane | 2005-10-19 02:21:35 | Re: Small plperl documentation patch |