Re: Small plperl documentation patch
От | Andrew Dunstan |
---|---|
Тема | Re: Small plperl documentation patch |
Дата | |
Msg-id | 43565AEA.4070803@dunslane.net обсуждение исходный текст |
Ответ на | Re: Small plperl documentation patch ("Greg Sabino Mullane" <greg@turnstep.com>) |
Список | 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 по дате отправления: