11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.43 2005/08/12 21:42:53 momjian Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.44 2005/08/24 18:56:07 tgl Exp $
33-->
44
55 <chapter id="plperl">
@@ -46,46 +46,18 @@ $PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.43 2005/08/12 21:42:53 momjian E
4646 <para>
4747 To create a function in the PL/Perl language, use the standard
4848 <xref linkend="sql-createfunction" endterm="sql-createfunction-title">
49- syntax. A PL/Perl function must always return a scalar value. You
50- can return more complex structures (arrays, records, and sets)
51- in the appropriate context by returning a reference.
52- Never return a list. Here follows an example of a PL/Perl
53- function.
49+ syntax:
5450
5551<programlisting>
5652CREATE FUNCTION <replaceable>funcname</replaceable> (<replaceable>argument-types</replaceable>) RETURNS <replaceable>return-type</replaceable> AS $$
5753 # PL/Perl function body
5854$$ LANGUAGE plperl;
5955</programlisting>
60- The body of the function is ordinary Perl code.
56+ The body of the function is ordinary Perl code. A PL/Perl function must
57+ always return a scalar value. You can return more complex structures
58+ (arrays, records, and sets) by returning a reference, as discussed below.
59+ Never return a list.
6160 </para>
62- <para>
63- As with ordinary Perl code, you should use the strict pragma,
64- which you can do in one of two ways:
65-
66- <itemizedlist>
67- <listitem>
68- <para>
69- Globally, by adding <quote>plperl</quote> to the list of <xref
70- linkend="guc-custom-variable-classes"> and setting
71- <literal>plperl.use_strict</literal> to true in
72- <filename>postgresql.conf</filename>
73- </para>
74- </listitem>
75- <listitem>
76- <para>
77- One function at a time, by using PL/PerlU (you must be database
78- superuser to do this) and including
79-
80- <programlisting>
81- use strict;
82- </programlisting>
83-
84- in the function body.
85- </para>
86- </listitem>
87- </itemizedlist>
88- </para>
8961
9062 <para>
9163 The syntax of the <command>CREATE FUNCTION</command> command requires
@@ -205,13 +177,13 @@ SELECT * FROM perl_row();
205177
206178 <para>
207179 PL/Perl functions can also return sets of either scalar or
208- composite types.In general, you'll want to return rows one at a
209- time both to speed up startup time and to keep from queueing up
180+ composite types.Usually you'll want to return rows one at a
181+ time, both to speed up startup time and to keep from queueing up
210182 the entire result set in memory. You can do this with
211183 <function>return_next</function> as illustrated below. Note that
212184 after the last <function>return_next</function>, you must put
213- either <literal>return; </literal> or (better) <literal>return
214- undef; </literal>
185+ either <literal>return</literal> or (better) <literal>return
186+ undef</literal>.
215187
216188<programlisting>
217189CREATE OR REPLACE FUNCTION perl_set_int(int)
@@ -237,7 +209,7 @@ $$ LANGUAGE plperl;
237209 contains either scalars, references to arrays, or references to
238210 hashes for simple types, array types, and composite types,
239211 respectively. Here are some simple examples of returning the entire
240- result set asa reference:
212+ result set asan array reference:
241213
242214<programlisting>
243215CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
@@ -267,6 +239,27 @@ SELECT * FROM perl_set();
267239 it is a hazard if you declare a <application>PL/Perl</> function
268240 as returning a domain type.
269241 </para>
242+
243+ <para>
244+ If you wish to use the <literal>strict</> pragma with your code,
245+ the easiest way to do so is to <command>SET</>
246+ <literal>plperl.use_strict</literal> to true. This parameter affects
247+ subsequent compilations of <application>PL/Perl</> functions, but not
248+ functions already compiled in the current session. To set the
249+ parameter before <application>PL/Perl</> has been loaded, it is
250+ necessary to have added <quote><literal>plperl</></> to the <xref
251+ linkend="guc-custom-variable-classes"> list in
252+ <filename>postgresql.conf</filename>.
253+ </para>
254+
255+ <para>
256+ Another way to use the <literal>strict</> pragma is to just put
257+ <programlisting>
258+ use strict;
259+ </programlisting>
260+ in the function body. But this only works for <application>PL/PerlU</>
261+ functions, since <literal>use</> is not a trusted operation.
262+ </para>
270263 </sect1>
271264
272265 <sect1 id="plperl-database">