<?xml version="1.0" encoding="windows-1252"?>
<node id="138176" title="Use modules with an import list on the command line" created="2002-01-11 22:14:00" updated="2005-08-12 08:26:18">
<type id="956">
perltutorial</type>
<author id="17000">
Ovid</author>
<data>
<field name="doctext">
&lt;p&gt;Short and to the point.  This is probably too simple to deserve the title of "Tutorial", but this is where this is where some Monks look.&lt;/p&gt;

&lt;p&gt;I've noticed that occassionally people try to use the command line, but don't quite "get" how to use modules and the import list.  It's fairly simple.  Use the &lt;tt&gt;-M&lt;/tt&gt; command line switch, followed by the module name.  For example, the following are equivalent:&lt;/p&gt;

&lt;code&gt;
    use LWP::Simple;
    getprint( "http://www.perlmonks.org/" );

    # command line:

    perl -MLWP::Simple -e 'getprint( "http://www.perlmonks.org/" )'
&lt;/code&gt;

&lt;p&gt;Some modules either require an import list be specified or are easier to use with an import list.  In this case, use the &lt;tt&gt;-M&lt;/tt&gt; switch followed by an '=', with import items separated by commas.&lt;/p&gt;

&lt;code&gt;
    use CGI qw/:standard *table/;
    print start_table( { border =&gt; 2 } );

    # command line

    perl -MCGI=:standard,*table -e 'print start_table({-border=&gt;2})'
&lt;/code&gt;

&lt;p&gt;There, that wasn't too painful, was it?&lt;/p&gt;</field>
</data>
</node>
