in reply to find out, if perl is started with the -c switch

If you need to know this because you are grabbing resources in BEGIN blocks and want to avoid doing that when it is just a compile check, it would probably be better to turn the BEGIN block into an INIT block instead (which is executed only after compilation is complete, at the beginning of the runtime phase), thus avoiding the need for the check.

See perlmod for the gory details about BEGIN, CHECK, INIT and END blocks.

Hugo

  • Comment on Re: find out, if perl is started with the -c switch

Replies are listed 'Best First'.
Re^2: find out, if perl is started with the -c switch
by grinder (Bishop) on Sep 23, 2005 at 13:30 UTC

    INIT blocks, hmmm, that reminds me, there was a thread on this sometime back: Which phase am I in?. In that thread, tilly pointed out that that require'ing a module will skip the INIT blocks:

    #! /usr/local/bin/perl -w use lib '.'; require 'foo.pm'; print "running\n"; # foo.pm package foo; INIT { warn "foo init\n" } 1;

    Running the above produces...

    Too late to run INIT block at foo.pm line 2.

    ... which may be something for the OP to keep in mind.

    • another intruder with the mooring in the heart of the Perl

Re^2: find out, if perl is started with the -c switch
by borisz (Canon) on Sep 23, 2005 at 17:24 UTC
    That is what I have in mind. But the modul in question is loaded with use so $^Cis my rescue.
    Boris