in reply to Re^3: did you mean python
in thread did you mean python

Thank you bliako! execv("/usr/bin/python3", argv) did the trick. Now I have a Perl interpreter that runs python, whoa:

Made 3 files:

python.pl: print join " ", "hello", "world\n" python.py: print("hello", "world", sep=" ") pythone.py: import os print(os.environ['hello'])
Got 3 results:
% python python.pl It parses as Perl so I am running it ... hello world % python python.py Can't modify constant item in scalar assignment at python.py line 1, n +ear "" ") " Execution of python.py aborted due to compilation errors. I guess it is &*^#$* pyton /sic/ ... hello world % export hello="hello world" % python pythone.py syntax error at pythone.py line 2, near "environ[" Execution of pythone.py aborted due to compilation errors. I guess it is &*^#$* pyton /sic/ ... hello world
How do I silence the error message from perl?

Replies are listed 'Best First'.
Re^5: did you mean python
by bliako (Abbot) on Jan 28, 2026 at 19:41 UTC

    I have updated the code in my original post to output syntax errors and debug messages only if env var PERL_PYTHON_EXECUTOR_DEBUG is set (e.g. PERL_PYTHON_EXECUTOR_DEBUG=1 python my.pl)

    I hope this serves as a springboard to experimenting with Perl embedded in C (you can run oneliner regexes in your code for example). and, why not?, XS.

    Perl is great.

    bw, bliako

    p.s. there is github-linguist which detects the type of comp.language.

Re^5: did you mean python
by Anonymous Monk on Jan 29, 2026 at 04:01 UTC
    > How do I silence the error message from perl?

    I just changed this line

    printf("It parses as Perl so I am running it ...\n");
    to this
    fprintf(stderr, "It parses as Perl so I am running it ...\n");
    so i can silence or redirect stderr with 2>&1- or 2>logfile

      Anon, with your redirection you will mix stderr messages from PARSING your input script (as perl, with perl_parse()) with stderr messages from RUNNING it (if it is indeed perl, with perl_run()). What I mean is that if your script, for example, fails to find a file during runtime, this will go to the logger file, mixed with all the possible syntax errors while assessing if perl or python. Well it is a solution.

      However, if you use the latest version of what I provided (see the modified C program in here: Re: did you mean python), you will have the syntax errors (via stderr) redirected to a logger file and then stderr will be reinstated to what it usually is so that you will have the runtime errors to your terminal. This behaviour is controlled by an env variable. You can modify the C program to provide the logger filename with another env variable.

      bw, bliako

      In the original version of the program:
      /* python.c - 27/01/2026 by bliako (bliako at cpan org) for https://perlmonks.org/?node_id=11167241 Run it either with a Perl CLI and a Perl script, like you would normally do with perl script.pl, perl -e ... etc. or with a python CLI and a python script. If the script does not parse as valid Perl code, it will pass the CLI and the script to a python interpreter. CAVEAT: it will fallback to python if your script is Perl but has syntax errors. compile it with: gcc python.c -o python `perl -MExtUtils::Embed -e ccopts -e ldopt +s` */ #include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ /* You gotta love Perl */ int main(int argc, char **argv, char **env) { PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; int ret = perl_parse(my_perl, NULL, argc, argv, (char **)NULL); if( ret ){ perl_destruct(my_perl); perl_free(my_perl); // add here language detection logic, // various options available open source fprintf(stderr, "I guess it is &*^#$* pyton /sic/ ...\n"); execvpe("/usr/bin/python", argv, env); } printf("It parses as Perl so I am running it ...\n"); perl_run(my_perl); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); exit(EXIT_SUCCESS); }