Unix Technical Forum

Small plperl documentation patch

This is a discussion on Small plperl documentation patch within the Pgsql Patches forums, part of the PostgreSQL category; --> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 NotDashEscaped: You need GnuPG to verify this message Using $a and $b for ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 12:59 AM
Greg Sabino Mullane
 
Posts: n/a
Default Small plperl documentation patch


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message


Using $a and $b for temporary vars are bad form for our example,
as they have special meaning in Perl.

Index: plperl.sgml
================================================== =================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/plperl.sgml,v
retrieving revision 2.46
diff -r2.46 plperl.sgml
121,124c121,124
< my ($a,$b) = @_;
< if (! defined $a) {
< if (! defined $b) { return undef; }
< return $b;
---
> my ($x,$y) = @_;
> if (! defined $x) {
> if (! defined $y) { return undef; }
> return $y;

126,128c126,128
< if (! defined $b) { return $a; }
< if ($a &gt; $b) { return $a; }
< return $b;
---
> if (! defined $y) { return $x; }
> if ($x &gt; $y) { return $x; }
> return $y;


--
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200510181742
http://biglumber.com/x/web?pk=2529DF...9B906714964AC8

-----BEGIN PGP SIGNATURE-----

iD8DBQFDVWyGvJuQZxSWSsgRApOzAJ9edQHEDRysEx0nLlI0hV 7v1bZikQCgyVnU
Rdouv5dEUTrW9TmZ4DExwjs=
=mi+E
-----END PGP SIGNATURE-----



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 12:59 AM
Andrew Dunstan
 
Posts: n/a
Default Re: Small plperl documentation patch


Patch applied, thanks. I actually told somebody off roundly about this
not long ago.

cheers

andrew

Greg Sabino Mullane wrote:

>
>Using $a and $b for temporary vars are bad form for our example,
>as they have special meaning in Perl.
>
>

[snip]


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 12:59 AM
Tom Lane
 
Posts: n/a
Default Re: Small plperl documentation patch

"Greg Sabino Mullane" <greg@turnstep.com> writes:
> Using $a and $b for temporary vars are bad form for our example,
> as they have special meaning in Perl.


Please, tell me that isn't so. $a is a reserved name now? What was
Larry thinking?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 12:59 AM
Greg Sabino Mullane
 
Posts: n/a
Default Re: Small plperl documentation patch


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


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.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200510182220
http://biglumber.com/x/web?pk=2529DF...9B906714964AC8

-----BEGIN PGP SIGNATURE-----

iD8DBQFDVa2qvJuQZxSWSsgRAoMSAJ4i+TlQOYUw5w8VCLqsSK akfgaWfQCfeqGo
n5Rn3XwUZZgwdHrs/7i3GNI=
=/0mE
-----END PGP SIGNATURE-----



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 12:59 AM
Andrew Dunstan
 
Posts: n/a
Default Re: Small plperl documentation patch



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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com