Re: Small plperl documentation patch - Mailing list pgsql-patches

From Andrew Dunstan
Subject Re: Small plperl documentation patch
Date
Msg-id 43565AEA.4070803@dunslane.net
Whole thread Raw
In response to Re: Small plperl documentation patch  ("Greg Sabino Mullane" <greg@turnstep.com>)
List 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

pgsql-patches by date:

Previous
From: "Greg Sabino Mullane"
Date:
Subject: Re: Small plperl documentation patch
Next
From: Christopher Kings-Lynne
Date:
Subject: Error in ORDER BY on check constraints in psql