andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:
luckynumber.tuse strict; use warnings; use Getopt::Long; my $luckynumber = undef; GetOptions("luckynumber=i" => \$luckynumber) or die("GetOptions failed +"); die "missing argument luckynumber" unless defined($luckynumber); print "Lucky number is " . $luckynumber . "\n";
Running the test yields:use warnings; use strict; use Test::More; use Test::Exception; BEGIN { plan tests => 2, todo => [] } # ------ load script without arg - expect failure throws_ok { require 'luckynumber.pl' } qr/missing argument/, 'needs argument'; # ------ load script with arg - expect ok ok( require 'luckynumber.pl --luckynumber=42', 'script loaded ok');
Is there a way to pass arguments to a script using require?$ prove luckynumber.t luckynumber....ok 1/2Can't locate luckynumber.pl --luckynumber=42 in @ +INC ..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Argument in require statement
by almut (Canon) on May 21, 2007 at 11:24 UTC | |
|
Re: Argument in require statement
by andreas1234567 (Vicar) on May 21, 2007 at 11:31 UTC | |
|
[OT] Re: Argument in require statement
by jettero (Monsignor) on May 21, 2007 at 12:19 UTC |