I have a script (relevent code below) that evaluates some command line options. One of these options prints out the version and exits. The thing I don't like is that it takes a few seconds to print out the version. Not a big deal, but a little irritating.

I know the reason is all of the modules being 'use'ed. I know I could explicitely import the important parts of the modules and that may help, but I'm not sure. If I comment out all the 'use' lines except for 'use Getopt::Long' the './program.pl --version' comes back immediately. This is the type of performance I would like when the whole thing is done.

Does anyone have any ideas on how I could speed this up?

TIA, gnu.

code below

use strict; use IO::Select; use IO::Socket; use Fcntl; use POSIX qw(:signal_h WNOHANG); use Net::SNMP; use DBI; use Sys::Hostname; use Getopt::Long qw(:config pass_through ); $|++; umask(0177); (my $VERSION = '$Revision: 1.23 $') =~ s/\$(.+) \$/$1/; my $MAXCHILDREN = 10; my $inputFile = "./mping.lookup"; my $path = "./unix_socket"; my $OID = '.1.3.6.1.4.1.15102.2.1.1.1'; my $interval = 60; my %source; my %failures; my $dump = 0; my $run = 0; my $version = 0; my %options = ( 'version' => \$version, 'children=i' => \$MAXCHILDREN, 'input' => \$inputFile, 'socket' => \$path, 'dump' => \$dump, 'run' => \$run, ); $SIG{TERM} = $SIG{INT} = sub { unlink $path; exit 0 }; GetOptions(%options); if (${$options{dump}}) { print $VERSION,"\n"; print "There are $MAXCHILDREN child processes by default\n"; print "Input file is ",${$options{input}},":\n"; print "Comm socket is ",${$options{socket}},":\n"; exit if ! ${$options{run}}; } if (${$options{version}}) { print $VERSION,"\n"; exit if ! ${$options{run}}; }

In reply to Script Startup Time by gnu@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.