From: Bruce Momjian Date: Wed, 18 Aug 2004 03:37:56 +0000 (+0000) Subject: The enclose patch clarifies and makes a more useful example for the X-Git-Tag: REL8_0_0BETA2~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f0a19c2638ced556ce1fc4a7f61383131c9a9e9;p=thirdparty%2Fpostgresql.git The enclose patch clarifies and makes a more useful example for the Global Values in PL/Perl section of the documents. David Fetter --- diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index cc24755615a..4080a80b7ef 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -1,5 +1,5 @@ @@ -317,23 +317,25 @@ $$ LANGUAGE plperl; Global Values in PL/Perl - You can use the %_SHARED to store data between function calls. WHY -IS THIS A HASH, AND NOT A HASH REF? + You can use the %_SHARED to store data between function calls. For example: -CREATE OR REPLACE FUNCTION set_var(TEXT) RETURNS TEXT AS $$ - $_SHARED{first} = 'Hello, PL/Perl!'; - return 'ok'; +CREATE OR REPLACE FUNCTION set_var(name TEXT, val TEXT) RETURNS TEXT AS $$ + if ($_SHARED{$_[0]} = $_[1]) { + return 'ok'; + } else { + return "Can't set shared variable $_[0] to $_[1]"; + } $$ LANGUAGE plperl; -CREATE OR REPLACE FUNCTION get_var() RETURNS text AS $$ - return $_SHARED{first}; +CREATE OR REPLACE FUNCTION get_var(name TEXT) RETURNS text AS $$ + return $_SHARED{$_[0]}; $$ LANGUAGE plperl; -SELECT set_var('hello plperl'); -SELECT get_var(); +SELECT set_var('sample', $q$Hello, PL/Perl! How's tricks?$q$); +SELECT get_var('sample');