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

Dear Monks

An installation I am doing says to run this line of code as a test but I don't know what it means perl -e ';' -MCGI I don;t know much perl but I thought the -e flag meant to execute the line of code and then exit. I don't know what I should expect to see as nothing happens when I run this line

Many thanks

Replies are listed 'Best First'.
Re: perl -e ';' -MCGI
by Fletch (Bishop) on Oct 28, 2010 at 13:26 UTC

    You're correct. Your example gives perl the code ; to execute (i.e. an empty statement; personally I tend to use -e 0 since it accomplishes the same thing and doesn't require quoting to prevent it from being interpreted by the shell). If nothing happens that's good, as it means that the CGI module was found and loaded correctly. Had it not found the module or something blew up you would have instead seen an error (and you could experimentally verify this by trying to load a non-existent module, e.g. perl -MThroatwarbler::Mangrove -e 0).

    Update: Erm, anonomonk protestations to the contrary aside, either order works as I said.

    $ perl -e 0 -MThroatwarbler::Mangrove Can't locate Throatwarbler/Mangrove.pm in @INC (@INC contains: /opt/lo +cal/lib/perl5/site_perl/5.8.9/darwin-2level /opt/local/lib/perl5/site +_perl/5.8.9 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendo +r_perl/5.8.9/darwin-2level /opt/local/lib/perl5/vendor_perl/5.8.9 /op +t/local/lib/perl5/vendor_perl/5.8.8 /opt/local/lib/perl5/vendor_perl/ +5.8.8/darwin-2level /opt/local/lib/perl5/vendor_perl /opt/local/lib/p +erl5/5.8.9/darwin-2level /opt/local/lib/perl5/5.8.9 .). BEGIN failed--compilation aborted. $ perl -MThroatwarbler::Mangrove -e 0 Can't locate Throatwarbler/Mangrove.pm in @INC (@INC contains: /opt/lo +cal/lib/perl5/site_perl/5.8.9/darwin-2level /opt/local/lib/perl5/site +_perl/5.8.9 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendo +r_perl/5.8.9/darwin-2level /opt/local/lib/perl5/vendor_perl/5.8.9 /op +t/local/lib/perl5/vendor_perl/5.8.8 /opt/local/lib/perl5/vendor_perl/ +5.8.8/darwin-2level /opt/local/lib/perl5/vendor_perl /opt/local/lib/p +erl5/5.8.9/darwin-2level /opt/local/lib/perl5/5.8.9 .). BEGIN failed--compilation aborted. $ perl -v This is perl, v5.8.9 built for darwin-2level Copyright 1987-2008, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. $ perl5.10.0 -MThroatwarbler::Mangrove -e 0 Can't locate Throatwarbler/Mangrove.pm in @INC (@INC contains: /usr/lo +cal/lib/perl5/5.10.0/darwin-2level /usr/local/lib/perl5/5.10.0 /usr/l +ocal/lib/perl5/site_perl/5.10.0/darwin-2level /usr/local/lib/perl5/si +te_perl/5.10.0 .). BEGIN failed--compilation aborted. $ perl5.10.0 -e 0 -MThroatwarbler::Mangrove Can't locate Throatwarbler/Mangrove.pm in @INC (@INC contains: /usr/lo +cal/lib/perl5/5.10.0/darwin-2level /usr/local/lib/perl5/5.10.0 /usr/l +ocal/lib/perl5/site_perl/5.10.0/darwin-2level /usr/local/lib/perl5/si +te_perl/5.10.0 .). BEGIN failed--compilation aborted. $ perl5.10.0 -e 0 -MCGI $ perl5.10.0 -MCGI -e 0 $

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Not in his case, in his case -MCGI is the first argument to the ; program (; being the first argument to the -e switch)

        -e does not end the processing of the options.

        $ perl -e'print "a\n";' -e'print "b\n";' a b

        And an example with -M:

        $ perl -e'print "a\n";' -e'print "b\n";' -MO=Deparse print "a\n"; print "b\n"; -e syntax OK
        Actually yes, to get perl to stop processing switches after -e you need to use --,
        $ perl -le"print for @ARGV, keys %INC " -MCGI -- -MCGI -MCGI warnings/register.pm Carp.pm vars.pm strict.pm Exporter.pm constant.pm warnings.pm CGI/Util.pm overload.pm CGI.pm
      Many thanks
Re: perl -e ';' -MCGI
by Your Mother (Archbishop) on Oct 28, 2010 at 13:43 UTC

    It's a minor savings but I do find myself typing this kind of thing a fair amount (I have a couple versions aliases too) so I suggest it-

    perl -MCGI -e1

    There are other useful switches for testing. See the switches section in perlrun for enough options to make your head explode.

    moo@cow>perl -MCGI -we'print' Use of uninitialized value in print at -e line 1.
Re: perl -e ';' -MCGI
by Anonymous Monk on Oct 28, 2010 at 13:27 UTC