in reply to [Solved] Parameter injection for testing

my $param = shift;

$param is a lexical variable so you have no way of getting at it. Make it a global variable and you can get at it from the outside:

our $param = shift;

... or even better, consider initializing the parameters from @ARGV, and doing so only in main, or passing @ARGV explicitly to main:

say main(@ARGV) unless caller(); sub main { my( @args ) = @_; GetOptionsFromArray( \@args, ... ); $param //= 'World'; return 'Hello ' . $param; }

Replies are listed 'Best First'.
Re^2: Parameter injection for testing
by davies (Monsignor) on Aug 24, 2022 at 15:17 UTC

    Thank you. I had tried something using our, but it was when I was floundering and obviously I did it wrong. The modulino will have lots of optional arguments and passing them all by name would be a pain. I may look at passing parameters when the modulino is closer to completion, but I am a fan of Getopt::Long, which does lots of things I like.

    Regards,

    John Davies