1

I am trying to do something like this: There are:

package Module;
use base 'Exporter';
our @EXPORT = qw(print);

sub print {
    my $nr = shift;
    print "$nr\n";
    if ($nr >= 5) {
        print "greater\n";
    } else {
        print "smaller\n";
    }
}

1;

and

main.pl :

use My::Module;
my $number = 7;
Module->print($number);

The problem is that when I run it I get this :

Module smaller

can anyone help me figure out what I am doing wrong?

1 Answer 1

1

When the arrow operator is used, the thing on the left is implicitly passed as the first parameter. You want to use Module::print($number);

Sign up to request clarification or add additional context in comments.

2 Comments

See the "Method Invocation" section in the documentation for perlobj: perldoc.perl.org/perlobj.html#Method-Invocation
You also don't want to export print if you're going to call it by its fully-qualified name. And you should probably name it something else since print is a builtin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.