ddebrito has asked for the wisdom of the Perl Monks concerning the following question:

I've got BEGIN routine that needs to test if the -c switch is in use. I don't see any internal global variables that define this compilation flag/switch. Does anyone know how to test if the -c perl switch is set?

Replies are listed 'Best First'.
Re: Testing for -c perl switch
by liverpole (Monsignor) on Apr 18, 2007 at 20:03 UTC
    Hi ddebrito,

    Yes ... from perlvar:

    $COMPILING $^C The current value of the flag associated with the -c switch. Mainly of use with -MO=... to allow code to alter its behavio +r when being compiled, such as for example to AUTOLOAD at compi +le time rather than normal, deferred loading. See perlcc. Set- ting "$^C = 1" is similar to calling "B::minus_c".

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      $^C does the trick.

      I need to update my Camel book. It's only the 2nd edition and did not cover $^C

        Your manual came with your copy of perl. Its up to date.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: Testing for -c perl switch
by Bloodnok (Vicar) on Apr 19, 2007 at 13:19 UTC
    ... something I learnt only yesterday, if your perl is 5.005ish or later, try testing the $^C variable.

    HTH ,

    Software is the only product guaranteed to be not fully working at point of delivery.