In order to see these concepts in action, take a look at the following listing, which uses PL/Perl to implement the same function that we saw in Chapter 4, Stored Procedures, when generating fake tuples. As you can see, the declaration of the function (the CREATE FUNCTION part) is the same as the PL/pgSQL counterpart, while the function implementation (the AS part) is pure Perl 5 code. Since the function needs to compute a hash using an external module (Digest), the function is declared as plperlu.
The function first assigns a context variable, $max, to the first and only argument passed to the function itself, which is the limit of the result set to be generated. After that, a scalar variable, $current_tuple ...