I have test_utils.pm:
package TestUtils;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw / print_diagnostic /;
sub print_diagnostic { <some_code_here> }
And I'd like to call print_diagnostic
from my main script tester.pl which is located in the same folder (I've used this solution):
#!/usr/bin/perl
use lib dirname (__FILE__);
use test_utils qw (:ALL);
print_diagnostic(<some_message>);
The problem is that I'm getting
Undefined subroutine &main::print_diagnostic called at ...
Calling the function with explicit package name TestUtils::print_diagnostic
works fine, but for various reasons I do want to call it w/o such a prefix.
use test_utils qw(print_diagnostic);
and
require test_utils;
yields the same results.
I've dug over few scores of similar questions, tried the answers and "solutions", but all that doesn't seem to work for me, and I'm getting really confused with all that "export", "import" and all the things around it, that I can't seize these concepts, so counterintuitive, comparing C++ and Java.
All what I want to do, is to split very complex scripts into several modules and reuse the code (now there is a lot of duplication).