Perltex for global use

To provide clean and explicit code, I usually

use strict;

      

when programming Perl. I would like to keep this habit in perltex too.

So, where should I put this statement use strict;

that he managed all subsequent calls \perldo

, \perlnewcommand

, \perlnewenvironment

, \perlrenewcommand

and \perlrenewenvironment

in perltex input file?

The following perltex example file works without raising the error:

\documentclass[12pt]{article}

\usepackage{perltex}

    \perldo{
        my $scalar = "ok";
        our @array = qw( array is fine );
        %HASH = (
            subject => "hash",
            result => "perfect"
        );
        use strict;
    }

    \perlnewcommand\printscalar{
        return $scalar;
    }

    \perlnewcommand\printarray{
        return join ", ", @array;
    }

    \perlnewcommand\printhash{
        return join ", ", map { sprintf "%s = %s", $_, $HASH{$_} } keys %HASH;
    }

\begin{document}
    Scalar: \printscalar

    Array: \printarray

    Hash: \printhash
\end{document}

      

It produces something similar to

text output text

That no error is raised indicates that use strict;

the top argument is \perldo

not counted in the definition \printscalar

. The result also shows that the installation was $scalar

no longer known due to my

. To avoid such errors, I would like to receive the error

The global symbol "$ scalar" requires an explicit package name

when I forget to specify my

or our

when introducing a new variable.

A workaround to my problem is to include the statement

use strict;

      

in all commands \perldo

, ..., and this can be done using macros. However, I wonder if there is a way to avoid such repeated statements.

+3


source to share


1 answer


The perltex CTAN documentation gives in section 3.2.3 a list of loaded modules and pragmas. These include use strict;

.

The docs are a little unclear when this is the default, but it's under --nosafe

. Then this parameter should be a way to toggle and load these defaults.

Have you tried setting it only in the first command used (for example \perldo

)? This may be enough.



The parameter --permit

allows you to specify the "functions" described in Opcode , which is done using the Safe module . While I don't see how to use this directly, the discussion in Safe::reval

may be helpful.

I have no module installed here and cannot try it. I hope this is helpful.

As a final question, why not contact the author? You may have found a bug (in the documentation) as the observed behavior seems to be in conflict with the docs. Besides, it is quite possible to add it.

+1


source







All Articles