in reply to Passing value to a Perl module

You have not imported hello into script.pl. Change your use statement to:

use Foo qw/hello/;

and try again. See Exporter for examples.

Replies are listed 'Best First'.
Re^2: Passing value to a Perl module
by Anonymous Monk on Jan 10, 2018 at 16:15 UTC
    Yes I forgot to import the "hello" sub. Done that, I still can not print the variable "$hello" in the module, not in the script.
    Use of uninitialized value $hello in print at Foo.pm

      Indeed. Your module says:

      my $hello = hello(); sub hello { my $h = shift; return; } print $hello;

      So $hello is given the return value of hello() which is undef. You probably want to return $h instead.

      PS. I would strongly advise naming your variables and your subroutines with different names, otherwise it's going to get very confusing very quickly.

      PPS. and as stevieb quite rightly says, pass an argument when you call hello().

      Well, when you initialize the module by loading it, this executes:

      my $hello = hello();

      Then later, you try to print $hello. It's going to be uninitialized, because you're not sending a value into hello() in that call. Try: my $hello = hello('blah');

        I see that, I know that, but I am trying to pass the value from the script.pl to the module.pm
        hello('test'); has been called by the script.pl
        I can fix the uninitialized by using this in Foo.pm
         my $hello = hello() || '';
        But how can I send the value from the script.pl to the Foo.pm?