in reply to Script Startup Time

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

Replies are listed 'Best First'.
Re: Re: Script Startup Time
by gnu@perl (Pilgrim) on Sep 17, 2003 at 18:02 UTC
    Yeah, I had that, but I like to try and keep all my 'use' lines together. This does work by the way. Thanks.