I'm very new to Perl, and have recently encountered the following problem.
My Perl code must all reside within a single file (it's being called by another program I have no control of).
I now wish to make the script run with a flag (e.g., perl myscript.pl -T
for taint mode), although it is initially called without the flag. How can I do that, i.e., how do I "set the flag" from within the Perl file?
One idea that I've had is to make the file launch itself again (after being called without flags), this time with the -T
flag (by issuing a shell command such as system($^X, "myscript.pl -T", @ARGS);
). Would that work? Any better ideas?
myscript.pl
you can set taint mode by altering your shebang line to include-T
e.g.#!/usr/bin/env perl -T
– Casualty/path/to/myscript.pl
, you can simply add-T
to the shebang line. – Symploce-T
in the shebang line doesn't necessarily enable taint mode -- if the script is invoked withperl
from the shell without-T
, you get a fatal error – Mesquite-T
in the shebang is the simplest solution. It'll either work or your script won't start, telling you to try a more complex workaround. – Visible/path/to/myscript.pl
from a shell, for example, you can add-T
to the shebang line inmyscript.pl
to enable taint mode; if it callsperl /path/to/myscript.pl
, for example, adding-T
to the shebang line will cause an error as mob points out. – Symploce