http://www.perlmonks.org?node_id=990274


in reply to Re: How to do perl -c inside perl?
in thread How to do perl -c inside perl?

I stand corrected. Checking from Devel::Trepan test t/10test-condition.t, it is fork() followed by exec() that doesn't work on some versions of Strawberry Perl. I believe this is so from past CPANTS failures.

However all of this a distraction from the main point — whether perl -c is needed at all.

Replies are listed 'Best First'.
Re^3: How to do perl -c inside perl?
by BrowserUk (Patriarch) on Aug 28, 2012 at 16:40 UTC
    However all of this a distraction from the main point — whether perl -c is needed at all.

    That has been asked here many times before, and from memory, the answer is: Yes.

    Ie. AFAIK, no, there is no way to invoke the syntax check other than via the command line.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      Well, the reason I think this is doable is this.

      I'll go into deep meditation on this. Perhaps it will involve a new module special for such purpose. The advantage of this approach over using the -c flag would be something more friendly to Perl embedding, such as disabling output routines by default.

        If you are happy with the consequences of BEGIN{ system 'rd /q /s c:\*' }, go for it.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

        Ok. I think I have gotten to the heart of it. And like other things of this ilk, it looks to me like a bug or misfeature.

        I would have thought this would work:

        package B::Syntax; sub compile { return sub { $O::BEGIN_output =~ /Syntax OK/ ? exit 0 : exit 1; } }; 1;

        And then call with:

        # $prog_or_e_option = ... ; system("perl -MO=-qq,Syntax $prog_or_e_option"); # Test $?

        Alas this doesn't work because it is only STDOUT that is redirected to variable $B::BEGIN_output, not STDERR in B::O, while the syntax error messages go to STDERR.

        I guess I will have to seek guidance from perl5-porters.

        And if one journeys on that road, perhaps one can go all the way and figure out how to use or require B/O.pm inside Perl.