It's all a matter of order and where to BEGIN: ;-)
use strict; my $VERSION; my $MAXCHILDREN; use Getopt::Long qw(:config pass_through ); BEGIN { ($VERSION = '$Revision: 1.23 $') =~ s/\$(.+) \$/$1/; $MAXCHILDREN = 10; my %options = ( 'version' => \$version, 'children=i' => \$MAXCHILDREN, 'input' => \$inputFile, 'socket' => \$path, 'dump' => \$dump, 'run' => \$run, ); 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}}; } } use IO::Select; use IO::Socket; use Fcntl; use POSIX qw(:signal_h WNOHANG); use Net::SNMP; use DBI; use Sys::Hostname; $|++; umask(0177); 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; $SIG{TERM} = $SIG{INT} = sub { unlink $path; exit 0 };

This is untested. But the basic idea is that the code you need to execute so you can show the Version info, is moved to a BEGIN {} block, before you load any of the other modules you need.

Liz


In reply to Re: Script Startup Time by liz
in thread 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.